diff --git a/cron.go b/cron.go index 8d67d67..850dae3 100644 --- a/cron.go +++ b/cron.go @@ -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)) diff --git a/cron_test.go b/cron_test.go index d418204..d555178 100644 --- a/cron_test.go +++ b/cron_test.go @@ -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()