Documentation ¶
Overview ¶
Example (JobFunc) ¶
someJob := func(cancel <-chan struct{}) error { fin := make(chan struct{}) go func() { // do some work close(fin) }() select { case <-fin: // job finished normally case <-cancel: // job canceled, do some cancelling work } return nil } someJob(nil)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FixedDelayTask ¶
type FixedDelayTask struct {
// contains filtered or unexported fields
}
func (*FixedDelayTask) MustStart ¶
func (t *FixedDelayTask) MustStart()
func (*FixedDelayTask) MustStop ¶
func (t *FixedDelayTask) MustStop()
func (*FixedDelayTask) Start ¶
func (t *FixedDelayTask) Start() error
func (*FixedDelayTask) Stop ¶
func (t *FixedDelayTask) Stop() error
type FixedRateTask ¶
type FixedRateTask struct {
// contains filtered or unexported fields
}
func (*FixedRateTask) MustStart ¶
func (t *FixedRateTask) MustStart()
func (*FixedRateTask) MustStop ¶
func (t *FixedRateTask) MustStop()
func (*FixedRateTask) Start ¶
func (t *FixedRateTask) Start() error
func (*FixedRateTask) Stop ¶
func (t *FixedRateTask) Stop() error
type JobFunc ¶
type JobFunc func(cancel <-chan struct{}) error
User defined job. It's recommended that JobFunc respond to cancel channel.
type Task ¶
type Task interface { // Return the Task name Name() string // Start the Task, cannot start a Task twice or start a stopped Task Start() error // Start the Task, panic if error happened MustStart() // Stop the task, cannot stop a not started Task or stop a Task twice. // This function only send the stop signal to the Task, does not wait for JobFunc to finish. Stop() error // Stop the Task, panic if error happened MustStop() }
type TaskManager ¶
type TaskManager interface { // Register a Task and start it. // Once the Task is managed by TaskManager, you should not call Task // lifecycle function(Task.Stop, Task.Start) any more. Register(task Task) error // Call Task.Stop and unregister it // This function only send the stop signal to Task(s), returning doesn't mean JobFunc is stopped Unregister(name string) // Stop all the Task and unregister them UnregisterAll() }
Task manager
func NewTaskManager ¶
func NewTaskManager() TaskManager
Click to show internal directories.
Click to hide internal directories.