Added naive threading using dumb and simple goroutines.
This commit is contained in:
parent
4792581d4d
commit
881ca6fe4d
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user