Skip to content

Commit

Permalink
Revert "provide a better panic message when no jobs in scheduler and …
Browse files Browse the repository at this point in the history
…start blocking called (#501)" (#503)

This reverts commit b035fe3.
  • Loading branch information
JohnRoesler committed May 30, 2023
1 parent 5bc0245 commit 604aa9b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 16 deletions.
1 change: 0 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ func ExampleScheduler_Stop() {
fmt.Println(s.IsRunning())

s = gocron.NewScheduler(time.UTC)
_, _ = s.Every(1).Second().Do(task)

go func() {
time.Sleep(1 * time.Second)
Expand Down
5 changes: 0 additions & 5 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ func (s *Scheduler) SetMaxConcurrentJobs(n int, mode limitMode) {

// StartBlocking starts all jobs and blocks the current thread.
// This blocking method can be stopped with Stop() from a separate goroutine.
//
// There must be at least 1 job in the scheduler or a panic will occur.
func (s *Scheduler) StartBlocking() {
if len(s.Jobs()) == 0 {
panic("gocron: scheduler must have at least 1 job before calling StartBlocking")
}
s.StartAsync()
s.startBlockingStopChanMutex.Lock()
s.startBlockingStopChan = make(chan struct{}, 1)
Expand Down
10 changes: 0 additions & 10 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,6 @@ func TestScheduler_Stop(t *testing.T) {
})
t.Run("stops a running scheduler calling .Stop()", func(t *testing.T) {
s := NewScheduler(time.UTC)
_, err := s.Every(1).Second().Do(func() {})
require.NoError(t, err)

go func() {
time.Sleep(time.Second)
Expand Down Expand Up @@ -2707,11 +2705,3 @@ func TestScheduler_WithDistributedLocker_With_Name(t *testing.T) {
})
}
}

func TestScheduler_StartBlocking(t *testing.T) {
t.Run("panics if no jobs are added", func(t *testing.T) {
s := NewScheduler(time.UTC)
expected := "gocron: scheduler must have at least 1 job before calling StartBlocking"
assert.PanicsWithValue(t, expected, s.StartBlocking)
})
}

0 comments on commit 604aa9b

Please sign in to comment.