Skip to content

Commit 32d9c27

Browse files
committed
Merge pull request robfig#36 from bruth/issue-35
Return on Stop if cron is not running
2 parents e428092 + 9ae1873 commit 32d9c27

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cron.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ func (c *Cron) run() {
178178
}
179179
}
180180

181-
// Stop the cron scheduler.
181+
// Stop stops the cron scheduler if it is running; otherwise it does nothing.
182182
func (c *Cron) Stop() {
183+
if !c.running {
184+
return
185+
}
183186
c.stop <- struct{}{}
184187
c.running = false
185188
}

cron_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ func TestLocalTimezone(t *testing.T) {
189189
}
190190
}
191191

192+
// Test that calling stop before start silently returns without
193+
// blocking the stop channel.
194+
func TestStopWithoutStart(t *testing.T) {
195+
cron := New()
196+
cron.Stop()
197+
}
198+
192199
type testJob struct {
193200
wg *sync.WaitGroup
194201
name string

0 commit comments

Comments
 (0)