diff --git a/remind/remind.go b/remind/remind.go index ce2159d..ef9a86a 100644 --- a/remind/remind.go +++ b/remind/remind.go @@ -5,7 +5,6 @@ import ( "b612.me/stardb" "b612.me/startimer" "errors" - "fmt" "sync" "time" ) @@ -69,23 +68,24 @@ func innerLoadDB(db *stardb.StarDB, callback func(task Task)) (*Remind, error) { if len(res) != 0 { rem.tasks = make(map[int64]Task, len(res)) for _, task := range res { + itask := new(Task) + *itask = task tmr := startimer.NewTimer(time.Now()) - err = tmr.ImportRepeats(task.TmrInfo) + err = tmr.ImportRepeats(itask.TmrInfo) if err != nil { return nil, err } - tmr.SetRunCountLimit(int(task.Limit)) - task.timer = &tmr - task.timer.AddTask(func() { - rem.callbackFn(&task) + tmr.SetRunCountLimit(int(itask.Limit)) + itask.timer = &tmr + itask.timer.AddTask(func() { + rem.callbackFn(itask) }) - err = task.timer.Run() + err = itask.timer.Run() if err != nil { db.Exec(`delete from remind where id=?`, task.ID) continue } - rem.tasks[task.ID] = task - fmt.Printf("%v %+v\n", tmr.NextTimer(), task) + rem.tasks[itask.ID] = *itask } } return &rem, nil diff --git a/remind/reminde_test.go b/remind/reminde_test.go index db01260..38a6681 100644 --- a/remind/reminde_test.go +++ b/remind/reminde_test.go @@ -49,7 +49,7 @@ func TestRemind(t *testing.T) { } fmt.Println("length of remind", len(r.ListTasks())) if len(r.ListTasks()) < 2 { - tk, err := r.AddTask("每8秒提醒我吃饭", "干饭", []byte{1, 2, 3}) + tk, err := r.AddTask("每10秒提醒我吃饭", "干饭", []byte{1, 2, 3}) if err != nil { t.Fatal(err) }