Added naive threading using dumb and simple goroutines.

This commit is contained in:
A. Svensson 2015-05-25 14:48:16 +02:00
parent 4792581d4d
commit 881ca6fe4d

View File

@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"
"time"
_ "github.com/mattn/go-sqlite3"
@ -49,16 +50,28 @@ func main() {
var (
id int
title string
group sync.WaitGroup
)
for rows.Next() {
err := rows.Scan(&id, &title)
checkerror(err)
weeklyhistorygraph(db, id, title)
monthlyhistorygraph(db, id, title)
monthlyaveragedaygraph(db, id, title)
// Make a new dumb goroutine
group.Add(1)
go updategraphs(db, &group, id, title)
}
err = rows.Err()
checkerror(err)
// Wait for all goroutines to finish
group.Wait()
}
func updategraphs(db *sql.DB, group *sync.WaitGroup, id int, title string) {
defer group.Done()
weeklyhistorygraph(db, id, title)
monthlyhistorygraph(db, id, title)
monthlyaveragedaygraph(db, id, title)
}
func checkerror(err error) {