Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is the structure responsible for tracking the state of the bounded single-producer single-consumer queue.
func New ¶
New[T any] returns an empty single-producer single-consumer bounded queue. The queue has capacity for `size` elements of type `T`.
func (*Queue[T]) Advance ¶
func (q *Queue[T]) Advance()
Advance moves the consumer forward. Advance may be called after using the data returned from Front. Advance should be called by the consumer if and only if it follows a successful call to Front.
func (*Queue[T]) Commit ¶
func (q *Queue[T]) Commit()
Commit advances the back of the queue. Commit can be used in conjunction with Reserve to work on the underlying queue data and present them to the consumer. Commit should be called by the producer.
func (*Queue[T]) Front ¶
Front is a non-blocking variant of Pop. It returns the oldest element in the queue if the queue is not empty, otherwise the zero-value for the type. A boolean indicator of success or failure is included as a second return value. Contrary to Pop, subsequent calls to Front without a call to Advance will return the same element. Front should be called by the consumer.
func (*Queue[T]) Offer ¶
Offer adds the passed element to the queue if there is an available slot. Offer returns true if the item was added successfully, otherwise false. Offer should be called by the producer.
func (*Queue[T]) Pop ¶
func (q *Queue[T]) Pop() T
Pop returns the oldest element in the queue and removes it. Pop will block if no element is available. Pop should be called by the consumer.
func (*Queue[T]) Push ¶
func (q *Queue[T]) Push(el T)
Push adds the passed element to the queue. Push will block if the queue is full. Push should be called by the producer.
func (*Queue[T]) Reserve ¶
Reserve returns the underlying element which the next Push operation will overwrite, i.e. the next open slot at the back of the queue. Data retrieved through Reserve can be made available to the consumer using Commit. The Reserve-Commit pattern can be used to work on the pre-allocated queue items. Subsequent calls to Reserve without a call to Commit will return the same element. Reserve should be called by the producer.