diff --git a/db/db.go b/db/db.go index b4d3383..6aa19b0 100644 --- a/db/db.go +++ b/db/db.go @@ -10,12 +10,14 @@ import ( ) var ( - db *sqlx.DB + db *sqlx.DB + queryQueue = make(chan func(), 1000) ) func Connect(params string) (err error) { db, err = sqlx.Connect("mysql", params) db.Mapper = reflectx.NewMapper("json") + go processQueue() return } @@ -42,6 +44,17 @@ func mustSelectN(dest interface{}, query string, params interface{}) { } } +func Queue(fun func()) { + queryQueue <- fun +} + +func processQueue() { + for { + fun := <-queryQueue + fun() + } +} + func measure(op string, start time.Time) { duration := time.Since(start).Nanoseconds() outcome := "succeeded"