Documentation ¶
Overview ¶
Package latest provides concurrent data structures that waste the least possible work on state data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chan ¶
type Chan struct {
// contains filtered or unexported fields
}
Chan acts like a normal channel except that sending will not block. Either it will send immediately, buffer into the single buffer slot, or overwrite the data already in that buffer slot.
Chan is safe to use with a single writer and any number of readers.
func (*Chan) Close ¶
func (n *Chan) Close()
Close closes the underlying channel. After closing, you should never Push data.
Like a regular channel close, use care orchestrating Push and Close in different goroutines. In particular, if you Push and Close in different goroutines, you could cause a panic, due to sending on a closed channel.
func (*Chan) Pull ¶
func (n *Chan) Pull() interface{}
Pull blocks until it is able to receive on the channel.
func (*Chan) Push ¶
func (n *Chan) Push(x interface{})
Push sends x. It should never block.
Like a regular channel send, use care orchestrating Push and Close in different goroutines. In particular, if you Push and Close in different goroutines, you could cause a panic, due to sending on a closed channel.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker provides a worker goroutine that uses the Chan type from this package to send and receive data. This makes it ideal for coordinating work between goroutines when new work always invalidates old work and neither goroutine can afford to block waiting on the other.
Worker should always be constructed by calling NewWorker.
func NewWorker ¶
func NewWorker(work func(in interface{}) interface{}) Worker
NewWorker constructs a worker and launches a goroutine. The provided function will be run on each input to the Push method, and the return value will be available via Pull() or Raw(). Because the input and output are managed wtih Chans, the worker goroutine will only ever block waiting when there is no new input. It will never block trying to send output.
func (Worker) Close ¶
func (w Worker) Close()
Close shuts down the input channel. This will cause the worker goroutine to terminate once it finishes its current work (if any). You can tell when the worker is stopped when the channel returned by Raw() closes.
func (Worker) Pull ¶
func (w Worker) Pull() interface{}
Pull blocks until data is available on the output channel.