浏览代码

Break Start() into Start() (runs in separate go routine) and Run() (previous behavior)

Rob Figueiredo 13 年之前
父节点
当前提交
c2521cab59
共有 3 个文件被更改,包括 6 次插入2 次删除
  1. 1 1
      README.md
  2. 4 0
      cron.go
  3. 1 1
      cron_test.go

+ 1 - 1
README.md

@@ -12,7 +12,7 @@ them in their own goroutines.
 c := new(Cron)
 c.Add("0 5 * * * *", func() { fmt.Println("Every 5 minutes") })
 c.Add("@hourly", func() { fmt.Println("Every hour") })
-go c.Start()  // Scheduler blocks until stopped, so run it in its own goroutine.
+c.Start()
 ..
 // Funcs are invoked in their own goroutine, asynchronously.
 ...

+ 4 - 0
cron.go

@@ -50,6 +50,10 @@ func (c *Cron) Add(spec string, cmd func()) {
 }
 
 func (c *Cron) Start() {
+	go c.Run()
+}
+
+func (c *Cron) Run() {
 	// Figure out the next activation times for each entry.
 	now := time.Now()
 	for _, entry := range c.Entries {

+ 1 - 1
cron_test.go

@@ -55,7 +55,7 @@ func TestAddWhileRunning(t *testing.T) {
 func startAndSignal(cron *Cron) <-chan struct{} {
 	ch := make(chan struct{})
 	go func() {
-		cron.Start()
+		cron.Run()
 		ch <- struct{}{}
 	}()
 	return ch