async

package
v1.10.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2019 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package async contains a set of helper objects for async tasks and job queues.

Index

Constants

This section is empty.

Variables

View Source
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

func NewQueue(workers int, logic Logic) *WorkQueue

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) Add added in v1.6.1

func (wq *WorkQueue) Add(job Job)

Add pushes a new job to the queue.

func (*WorkQueue) Stop added in v1.6.1

func (wq *WorkQueue) Stop()

Stop stops the job queue and the workers.

func (*WorkQueue) Wait added in v1.6.1

func (wq *WorkQueue) Wait()

Wait stops until all the workers stopped.

func (*WorkQueue) WaitDone added in v1.6.1

func (wq *WorkQueue) WaitDone()

WaitDone stops until all jobs on the queue have been processed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL