base: Index | Examples | Files

package syncqueue

import ""



Package Files

lifo.go ordered_queue.go

type LIFO Uses

type LIFO struct {
    // contains filtered or unexported fields

LIFO implements a last-in, first-out producer-consumer queue. Thread safe.


q := syncqueue.NewLIFO()
v0, ok := q.Get()
fmt.Println("Item 0:", v0.(string), ok)
v1, ok := q.Get()
fmt.Println("Item 1:", v1.(string), ok)
v2, ok := q.Get()
fmt.Println("Item 2:", v2, ok)


Item 0: item1 true
Item 1: item0 true
Item 2: <nil> false

func NewLIFO Uses

func NewLIFO() *LIFO

NewFIFO creates an empty FIFO queue.

func (*LIFO) Close Uses

func (q *LIFO) Close()

Close informs the queue that no more objects will be added via Put().

func (*LIFO) Get Uses

func (q *LIFO) Get() (interface{}, bool)

Get removes the newest object added to the queue. It blocks the caller if the queue is empty.

func (*LIFO) Put Uses

func (q *LIFO) Put(v interface{})

Put adds the object in the queue.

type OrderedQueue Uses

type OrderedQueue struct {
    // contains filtered or unexported fields

OrderedQueue is a queue that orders entries on their way out. An inserter enqueues each entry with an index, and when the receiver dequeues an entry, the entries arrive in the sequential order of their indices. An OrderedQueue has a maximum size; if the queue contains the next entry, the queue will accept up to maxSize entries. If the queue does not yet contain the next entry, the queue will block an insert that would make the size equal to maxSize unless the new entry is the next entry to be dequeued.

func NewOrderedQueue Uses

func NewOrderedQueue(maxSize int) *OrderedQueue

Create a new OrderedQueue with size maxSize.

func (*OrderedQueue) Close Uses

func (q *OrderedQueue) Close(err error) error

Close the ordered queue. In the normal case, err should be nil, and Close tells the OrderedQueue that all calls to Insert have completed. The user may not call Insert() after calling Close(). The user may close the OrderedQueue prematurely with a non-nil err while some calls to Insert() and/or Next() are blocking; in this case those calls that are blocking will return with err.

func (*OrderedQueue) Insert Uses

func (q *OrderedQueue) Insert(index int, value interface{}) error

Insert an entry into the queue with the specified sequence index. Insert blocks if the insert would make the queue full and the new entry is not the one next one in the output sequence. The sequence index should start at zero.

func (*OrderedQueue) Next Uses

func (q *OrderedQueue) Next() (value interface{}, ok bool, err error)

Next returns true and the next entry in sequence if the next entry is available. Next blocks if the next entry is not yet present. Next returns (nil, false) if there are no more entries, and the queue is closed.

Package syncqueue imports 2 packages (graph) and is imported by 3 packages. Updated 2018-11-16. Refresh now. Tools for package owners.