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" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"sync"
"time" "time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -49,16 +50,28 @@ func main() {
var ( var (
id int id int
title string title string
group sync.WaitGroup
) )
for rows.Next() { for rows.Next() {
err := rows.Scan(&id, &title) err := rows.Scan(&id, &title)
checkerror(err) checkerror(err)
weeklyhistorygraph(db, id, title)
monthlyhistorygraph(db, id, title) // Make a new dumb goroutine
monthlyaveragedaygraph(db, id, title) group.Add(1)
go updategraphs(db, &group, id, title)
} }
err = rows.Err() err = rows.Err()
checkerror(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) { func checkerror(err error) {