Skip to content

Commit

Permalink
feat(cron): add IsRunning (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 authored Nov 19, 2024
1 parent 00dd070 commit 787f672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ func (c *Cron) Stop() context.Context {
return ctx
}

// IsRunning returns true if the cron scheduler is started.
func (c *Cron) IsRunning() bool {
return c.running
}

// entrySnapshot returns a copy of the current cron entry list.
func (c *Cron) entrySnapshot() []Entry {
entries := make([]Entry, len(c.entries))
Expand Down
12 changes: 12 additions & 0 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,18 @@ func TestStopAndWait(t *testing.T) {
})
}

func TestCron_IsRunning(t *testing.T) {
c := New()

assert.False(t, c.IsRunning())

c.Start()
assert.True(t, c.IsRunning())

c.Stop()
assert.False(t, c.IsRunning())
}

func TestMultiThreadedStartAndStop(*testing.T) {
cron := New()
go cron.Run()
Expand Down

0 comments on commit 787f672

Please sign in to comment.