Browse Source

Return on Stop if cron is not running

Signed-off-by: Byron Ruth <b@devel.io>
Byron Ruth 10 years ago
parent
commit
9ae18730f4
2 changed files with 11 additions and 1 deletions
  1. 4 1
      cron.go
  2. 7 0
      cron_test.go

+ 4 - 1
cron.go

@@ -178,8 +178,11 @@ func (c *Cron) run() {
 	}
 }
 
-// Stop the cron scheduler.
+// Stop stops the cron scheduler if it is running; otherwise it does nothing.
 func (c *Cron) Stop() {
+	if !c.running {
+		return
+	}
 	c.stop <- struct{}{}
 	c.running = false
 }

+ 7 - 0
cron_test.go

@@ -189,6 +189,13 @@ func TestLocalTimezone(t *testing.T) {
 	}
 }
 
+// Test that calling stop before start silently returns without
+// blocking the stop channel.
+func TestStopWithoutStart(t *testing.T) {
+	cron := New()
+	cron.Stop()
+}
+
 type testJob struct {
 	wg   *sync.WaitGroup
 	name string