modulepackage
0.0.0-20190106124920-6fba78e23b74
Repository: https://github.com/sdeoras/scheduler.git
Documentation: pkg.go.dev
# README
scheduler
this package provides an easy way to schedule functions using an event trigger.
scheduling a function
A timeout trigger can be defined as follows:
trigger := scheduler.NewTimeoutTrigger(time.Second)
which can then be used to schedule functions as follows:
group, ctx := scheduler.New(ctx, trigger)
where, ctx
in input is the parent context and one in output is to be used to pass during scheduling functions.
group.Go(ctx, func() error {
// your logic
return nil
})
Finally wait for all functions to return using Wait
:
// wait for func executions to be over.
err := group.Wait()
triggers
triggers can be of following types:
// a timeout trigger allows execution on a timeout
timeoutTrigger := scheduler.NewTimeoutTrigger(timeDuration)
// trigger now causes functions to execute immediately
triggerNow := scheduler.TriggerNow()
// similarly, an event can used to trigger functions, event being ctx.Done()
triggerOnEvent := scheduler.NewContextTrigger(ctx)
# Functions
New creates a new scheduler based on an input context and trigger mode.
NewChannelTrigger provides a new trigger based on a channel.
NewContextTrigger provides a new trigger based on a context.
NewTimeoutTrigger provides a new trigger based on a timeout.
TriggerNow provides an immediate trigger mechanism.
# Constants
No description provided by the author
No description provided by the author
# Interfaces
Scheduler defines interface to schedule execution of a func.
# Type aliases
Error is used to build error constants.