Documentation ¶
Overview ¶
package scheduler defines func scheduling interface and provides implementation for deferred execution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler interface { // Go executes function and returns a key which can be used to cancel func execution. Go(ctx context.Context, f func() error) string // Cancel cancels execution of func if pending execution. Cancel(key string) error // Wait waits for all functions dispatched using Go to finish. Wait() error }
Scheduler defines interface to schedule execution of a func.
func New ¶
New creates a new scheduler based on an input context and trigger mode. Scheduler will cancel all pending jobs if the input context is cancelled. Scheduler will trigger jobs based on trigger. It returns a context that should be used in each function. This output context is cancelled on first error in any of the scheduled jobs.
type Trigger ¶
type Trigger struct {
// contains filtered or unexported fields
}
func NewChannelTrigger ¶
func NewChannelTrigger(c chan struct{}) Trigger
NewChannelTrigger provides a new trigger based on a channel. Trigger fires when input chan is read.
func NewContextTrigger ¶
NewContextTrigger provides a new trigger based on a context. Trigger fires when input context context is done.
func NewTimeoutTrigger ¶
NewTimeoutTrigger provides a new trigger based on a timeout.