Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*config)
Option is a queue configuration option.
func Capacity ¶
Capacity is the amount of "in flight" items the queue can hold, not including any extra capacity in the input/output buffers. Assuming unbuffered input/output, this is the number of items that can be pushed to a queue before it begins to exhibit backpressure. A value of 8-16x the number of workers is probably a reasonable choice for most applications. Note that a queue always has a capacity at least equal to the number of workers, so `New(fn,Workers(7),Capacity(3))` results in a queue with capacity `7`. Defaults to 64.
func InputBuf ¶
InputBuf is the amount of buffer to be used in the input/push channel. Defaults to 0 (unbuffered).
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is a data processing helper which uses a worker pool to apply a closure to a series of values concurrently, preserving the correct ordering of results. It is essentially the concurrent equivalent of this:
for msg := range inputChannel { outputChannel <- workFunction(msg) }
In order to prevent indefinite memory growth within the queue due to slow consumption and/or workers, the queue will exert backpressure over its input channel once a configurable capacity is reached.
func (*Queue) Close ¶
Close permanently terminates all background operations. If the queue is not drained before closure, items may be lost.
func (*Queue) Pop ¶
func (q *Queue) Pop() <-chan interface{}
Pop accesses the queue's output channel. The type of the received value will match the output of the work function.
func (*Queue) Push ¶
func (q *Queue) Push() chan<- interface{}
Push accesses the queue's input channel. The type of sent values must match that expected by the queue's work function. If the queue was configured with a buffered input/push channel, non-blocking sends can be used as a heuristic for detecting backpressure due to queue capacity. This is not a perfect test, but the rate of false positives will be extremely low for a queue with a decent capacity and non-trivial work function.