Documentation ¶
Overview ¶
Package sched provides a job scheduler implementation that's able to fast-forward time. All methods of both the package and a Scheduler instance are thread-safe and can safely be used from within multiple goroutines.
Index ¶
- Constants
- Variables
- func Cancel(id Job) bool
- func Len() int
- func Offset() time.Duration
- func Scan(after Job, fn func(job Job, jobFn func()) bool) (ok bool)
- type Duration
- type Job
- type QueueReadWriter
- type QueueReader
- type QueueWriter
- type Scheduler
- func (s *Scheduler) AdvanceTime(by Duration) (newOffset Duration)
- func (s *Scheduler) AdvanceToNext() (newOffset, advancedBy Duration)
- func (s *Scheduler) Cancel(id Job) bool
- func (s *Scheduler) Len() int
- func (s *Scheduler) Now() Time
- func (s *Scheduler) Offset() time.Duration
- func (s *Scheduler) Scan(after Job, fn func(job Job, jobFn func()) bool) (ok bool)
- func (s *Scheduler) Schedule(in Duration, fn func()) (Job, error)
- type Time
- type TimeProvider
- type Timer
Constants ¶
const ( Nanosecond = time.Nanosecond Microsecond = time.Microsecond Millisecond = time.Millisecond Second = time.Second Minute = time.Minute Hour = time.Hour )
Variables ¶
var DefaultScheduler = New(0)
DefaultScheduler is the default Scheduler used by Schedule, Cancel, Now, AdvanceTime, AdvanceToNext, Len, Offset and Scan.
Functions ¶
Types ¶
type Duration ¶
func AdvanceTime ¶
AdvanceTime advances the current time by the given duration.
func AdvanceToNext ¶
func AdvanceToNext() (newOffset, advancedBy Duration)
AdvanceToNext advances the current time to the next job executing it immediately. Does nothing if no jobs are pending.
type Job ¶
Job is a unique job identifier.
type QueueReadWriter ¶
type QueueReadWriter interface { QueueReader QueueWriter }
type QueueReader ¶
type QueueWriter ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is a job scheduler.
func NewWith ¶
func NewWith( timeOffset Duration, t TimeProvider, q QueueReadWriter, ) *Scheduler
NewWith is similar to New but replaces the default time provider and queue implementation. If t == nil then standard time package is used by default. If q == nil then sched/internal/queue.Queue is used by default.
func (*Scheduler) AdvanceTime ¶
AdvanceTime advances the current time by the given duration.
func (*Scheduler) AdvanceToNext ¶
AdvanceToNext advances the current time to the next job executing it immediately. Does nothing if no jobs are pending.
func (*Scheduler) Cancel ¶
Cancel cancels a pending job and returns true. Returns false if no job was canceled.