Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRoutine means routine has invalid type ErrInvalidRoutine = errors.New("invalid routine") // ErrInvalidState means a task/group state is invalid for current operation (broken flow) ErrInvalidState = errors.New("invalid state") )
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a group of Tasks.
func (*Group) Add ¶
Add adds a Task. If the Group is running, `ErrInvalidState` error will be returned.
func (*Group) Log ¶ added in v1.0.2
Log sets a Logger. If the Group is running, `ErrInvalidState` error will be returned.
func (*Group) Run ¶
Run starts Group's Tasks. If the Group is running, `ErrInvalidState` error will be returned. Run will ignore any Task that is already running (i.e. Task.Run() return error).
func (*Group) Stop ¶
func (g *Group) Stop()
Stop requires Group's Tasks to stop. Does nothing if the Group is not running.
func (*Group) TokenOf ¶ added in v1.0.2
TokenOf returns specific Task Token. If the Task wasn't started by the Group or Group isn't running, `ErrInvalidState` will be returned.
type Logger ¶ added in v1.0.2
type Logger interface {
Log(...interface{})
}
Logger logs events for debug
type Recover ¶
type Recover func(interface{})
Recover is a callback function template that will be called on routine panic.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task is a named routine that does something in parallel.
func NewTask ¶
NewTask instance. Arg `routine` should be an entity of type: func(), func(*Token), func(...interface{}), func(*Token, ...interface{}). Otherwise `ErrInvalidRoutine` will be returned.
func (*Task) Log ¶ added in v1.0.2
Log sets a Logger. If the Task is running, `ErrInvalidState` error will be returned.
func (*Task) Recover ¶
Recover specifies a callback function that will be called in case of routine's panic.
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token controls a Task's lifetime.
func (*Token) Sleep ¶
Sleep sleeps specified amount of time or until related Task is requested to stop. Returns `true` if a stop-event received while sleeping. In general case this method is used from within a routine.