Signed-off-by: Byron Ruth <b@devel.io>
@@ -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
@@ -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