Documentation ¶
Overview ¶
Package async contains a set of helper objects for async tasks and job queues.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeout happens when there's a timeout ... doh. ErrTimeout = errors.New("timeout") )
Functions ¶
func WithTimeout ¶
func WithTimeout(tm time.Duration, cb TimedCallback) (interface{}, error)
WithTimeout will execute the callback and return its value or a ErrTimeout if its execution will exceed the provided duration.
Types ¶
type Job ¶
type Job interface{}
Job is the generic interface object representing the data being pushed to the jobs queue and being passed to the workers.
type Logic ¶
type Logic func(arg Job)
Logic is the implementation of the logic each worker will execute.
type TimedCallback ¶
type TimedCallback func() interface{}
TimedCallback represents a generic function with a return value.
type WorkQueue ¶ added in v1.6.1
type WorkQueue struct {
// contains filtered or unexported fields
}
WorkQueue is the object representing an async jobs queue with a given number of concurrent workers.
func NewQueue ¶
NewQueue creates a new job queue with a specific worker logic. If workers is greater or equal than zero, it will be auto scaled to the number of logical CPUs usable by the current process.
func (*WorkQueue) Stop ¶ added in v1.6.1
func (wq *WorkQueue) Stop()
Stop stops the job queue and the workers.