Fix race condition

This commit is contained in:
simon987
2019-03-01 22:48:09 -05:00
parent 840a4173bb
commit 13290d3c55
2 changed files with 36 additions and 29 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/simon987/task_tracker/config"
"io/ioutil"
"os"
"sync"
)
type Database struct {
@@ -14,12 +15,14 @@ type Database struct {
saveTaskStmt *sql.Stmt
workerCache map[int64]*Worker
assignMutex *sync.Mutex
}
func New() *Database {
d := Database{}
d.workerCache = make(map[int64]*Worker)
d.assignMutex = &sync.Mutex{}
d.init()