Version: v0.0.0-...-aed1ee4 Latest Latest

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 3 Imported by: 0



Package coalesce provides an in-order queue for collecting outputs from a producer to provide inputs to a consumer. Coalescing happens when an output has been produced more than once by the producer before being consumed. In this case the outputs are coalesced and delivered only once.



This section is empty.


This section is empty.


func IsClosedQueue

func IsClosedQueue(err error) bool

IsClosedQueue returns whether a given error is coalesce.errClosedQueue.


type Queue

type Queue struct {
	// contains filtered or unexported fields

Queue is a structure that implements in-order delivery of coalesced inputs. Operations on Queue are threadsafe and any number of producers may contribute to the queue and any number of consumers may receive, however, no fairness among consumers is guaranteed and it is possible for starvation to occur.

func NewQueue

func NewQueue() *Queue

NewQueue returns an initialized Queue ready for use.

func (*Queue) Close

func (q *Queue) Close()

Close closes the queue for inserts.

func (*Queue) Insert

func (q *Queue) Insert(i interface{}) (bool, error)

Insert adds i to the queue and returns true if i does not already exist. Insert returns an error if the Queue has been closed.

func (*Queue) IsClosed

func (q *Queue) IsClosed() bool

IsClosed reports if the queue is in a closed state.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the current length of the queue, useful for reporting statistics. Since the queue is designed to be operated on by one or more producers and one or more consumers, this return value only indicates what the length was at the instant it was evaluated which may change before the caller gets the return value.

func (*Queue) Next

func (q *Queue) Next(ctx context.Context) (interface{}, uint32, error)

Next returns the next item in the queue and the number of duplicates that were dropped, or an error if the Queue is empty and has been closed. Calls to Next are blocking.

Source Files

Jump to

Keyboard shortcuts

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