Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigFunc ¶
type ConfigFunc func(*scheduler)
ConfigFunc is a function used to initialize a new scheduler.
func WithClock ¶
func WithClock(clock glock.Clock) ConfigFunc
WithClock sets the clock used by the scheduler (useful for testing).
func WithInterval ¶
func WithInterval(interval time.Duration) ConfigFunc
WithInterval sets the interval at which the scheduler will invoke the scheduled function (default is one second). An interval of zero means no scheduled interval and the wrapped function will be invoked only by a call to Signal.
func WithSkipFirstInvocation ¶
func WithSkipFirstInvocation() ConfigFunc
WithSkipFirstInvocation will flag the first invocation (immediately after Start is called) to be skipped. The first invocation will be after the first call to Signal, Reset, or after the initial timeout period elapses.
func WithThrottle ¶
func WithThrottle(minInterval time.Duration) ConfigFunc
WithThrottle sets the minimum duration between two invocations of the scheduled function (there is no default minimum).
type Scheduler ¶
type Scheduler interface {
// Start the scheduler in a goroutine.
Start()
// Stop the scheduler.
Stop()
// Signal the scheduler to execute the function immediately. This method is
// always non-blocking, and may be ignored depending on if the scheduler is
// throttling signals or not. This method must only be called while the
// scheduler is active.
Signal()
// Reset the interval timer in the scheduler. This method must only be called
// while the scheduler is active.
Reset()
}
Scheduler periodically executes the a target function. A scheduler can be signaled to execute the function immediately as often as the user likes via the Signal method (if the scheduler is configured to allow it).
func NewScheduler ¶
func NewScheduler(target func(), configs ...ConfigFunc) Scheduler
NewScheduler creates a new scheduler that will invoke the target function.
