Documentation ¶
Overview ¶
Package task implements a simple asynchronous task management scheme.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrShuttingDown = errors.New("shutting down: cannot start a new task") ErrNoSuchTask = errors.New("no such task") )
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface interface {
Run() (interface{}, error)
}
Interface is the common interface implemented for a task that can be managed by a Manager.
Run executes the task and returns the result and/or an error.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps track of a set of tasks. Currently, it keeps tasks forever but it should have a way of expiring tasks.
func (*Manager) Shutdown ¶
Shutdown disallows new tasks from being started and waits until the existing tasks all complete. This returns an error only if the provided context is done before all the tasks have completed.
func (*Manager) Start ¶
Start initiates the execution of the provided task and returns the id. If Shutdown has been called, then this will return ErrShuttingDown.
func (*Manager) Wait ¶
Wait for the given task to be completed and return the result & error output of the task. Once a task completes, subsequent calls to this function will immediately return the outputs. If the provided context finishes before the task has completed, then the context error (cancelled or timeout) will be returned.
NOTE(aroman) Probably this should only be allowed to be called once succesfully (that is, not including the context timeout) and then expire the task to prevent excessive memory growth.