docs: clarify NextRun/NextRuns require scheduler to be started (#910)

* Initial plan

* docs: clarify NextRun and NextRuns return empty values until scheduler is started

Co-authored-by: JohnRoesler <19351306+JohnRoesler@users.noreply.github.com>

* docs: remove unhelpful inline comments from NextRun/NextRuns examples

Co-authored-by: JohnRoesler <19351306+JohnRoesler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/go-co-op/gocron/sessions/9686e808-ae5e-4bc8-ad00-f78a1a7b079d

* docs: restore inline comments for NextRun/NextRuns examples

Co-authored-by: JohnRoesler <19351306+JohnRoesler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/go-co-op/gocron/sessions/df5afb1e-5c66-4615-9967-a2efc2419d87

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JohnRoesler <19351306+JohnRoesler@users.noreply.github.com>
This commit is contained in:
Copilot 2026-03-20 11:58:16 -05:00 committed by GitHub
parent 102b2b2c8e
commit 5b307f56dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -267,6 +267,9 @@ func ExampleJob_nextRun() {
), ),
) )
// NextRun is only available after the scheduler has been started.
s.Start()
nextRun, _ := j.NextRun() nextRun, _ := j.NextRun()
fmt.Println(nextRun) fmt.Println(nextRun)
} }
@ -284,6 +287,9 @@ func ExampleJob_nextRuns() {
), ),
) )
// NextRuns is only available after the scheduler has been started.
s.Start()
nextRuns, _ := j.NextRuns(5) nextRuns, _ := j.NextRuns(5)
fmt.Println(nextRuns) fmt.Println(nextRuns)
} }

4
job.go
View File

@ -1190,8 +1190,12 @@ type Job interface {
// Name returns the name defined on the job. // Name returns the name defined on the job.
Name() string Name() string
// NextRun returns the time of the job's next scheduled run. // NextRun returns the time of the job's next scheduled run.
// This value is only available once the scheduler has been started
// with Scheduler.Start(). Before that, it returns the zero time value.
NextRun() (time.Time, error) NextRun() (time.Time, error)
// NextRuns returns the requested number of calculated next run values. // NextRuns returns the requested number of calculated next run values.
// These values are only available once the scheduler has been started
// with Scheduler.Start(). Before that, it returns nil.
NextRuns(int) ([]time.Time, error) NextRuns(int) ([]time.Time, error)
// RunNow runs the job once, now. This does not alter // RunNow runs the job once, now. This does not alter
// the existing run schedule, and will respect all job // the existing run schedule, and will respect all job