gf: github.com/johng-cn/gf/g/container/gqueue Index | Files

package gqueue

import "github.com/johng-cn/gf/g/container/gqueue"

Package gqueue provides a dynamic/static concurrent-safe queue.

Features:

1. FIFO queue(data -> list -> chan);

2. Fast creation and initialization;

3. Support dynamic queue size(unlimited queue size);

4. Blocking when reading data from queue;

Index

Package Files

gqueue.go

type Queue Uses

type Queue struct {
    C chan interface{} // Underlying channel for data reading.
    // contains filtered or unexported fields
}

func New Uses

func New(limit ...int) *Queue

New returns an empty queue object. Optional parameter <limit> is used to limit the size of the queue, which is unlimited in default. When <limit> is given, the queue will be static and high performance which is comparable with stdlib channel.

func (*Queue) Close Uses

func (q *Queue) Close()

Close closes the queue. Notice: It would notify all goroutines return immediately, which are being blocked reading using Pop method.

func (*Queue) Len Uses

func (q *Queue) Len() (length int)

Len returns the length of the queue.

func (*Queue) Pop Uses

func (q *Queue) Pop() interface{}

Pop pops an item from the queue in FIFO way. Note that it would return nil immediately if Pop is called after the queue is closed.

func (*Queue) Push Uses

func (q *Queue) Push(v interface{})

Push pushes the data <v> into the queue. Note that it would panics if Push is called after the queue is closed.

func (*Queue) Size Uses

func (q *Queue) Size() int

Size is alias of Len.

Package gqueue imports 3 packages (graph). Updated 2019-06-19. Refresh now. Tools for package owners.