From 03eb1fc104104ebc647ee2fdb96cb9735a9320e8 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 21 Aug 2014 15:56:34 +0800 Subject: [PATCH] toolbox: add notify when add & delete task --- toolbox/task.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/toolbox/task.go b/toolbox/task.go index 6931e189..8550b736 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -33,6 +33,7 @@ type bounds struct { var ( AdminTaskList map[string]Tasker stop chan bool + changed chan bool seconds = bounds{0, 59, nil} minutes = bounds{0, 59, nil} hours = bounds{0, 23, nil} @@ -411,6 +412,8 @@ func run() { e.SetNext(effective) } continue + case <-changed: + continue case <-stop: return } @@ -425,6 +428,13 @@ func StopTask() { // add task with name func AddTask(taskname string, t Tasker) { AdminTaskList[taskname] = t + changed <- true +} + +// add task with name +func DeleteTask(taskname string) { + delete(AdminTaskList, taskname) + changed <- true } // sort map for tasker @@ -578,4 +588,5 @@ func all(r bounds) uint64 { func init() { AdminTaskList = make(map[string]Tasker) stop = make(chan bool) + changed = make(chan bool) }