gqueue

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

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

并发安全的动态队列.

特点:
1. 动态队列初始化速度快;
2. 动态的队列大小(不限大小);
3. 取数据时如果队列为空那么会阻塞等待;

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	C chan interface{} // 队列数据读取
	// contains filtered or unexported fields
}

1、这是一个先进先出的队列(chan <-- list);

2、当创建Queue对象时限定大小,那么等同于一个同步的chan并发安全队列;

3、不限制大小时,list链表用以存储数据,临时chan负责为客户端读取数据,当从chan获取数据时,list往chan中不停补充数据;

4、由于功能主体是chan,那么操作仍然像chan那样具有阻塞效果;

func New

func New(limit ...int) *Queue

队列大小为非必须参数,默认不限制

func (*Queue) Close

func (q *Queue) Close()

关闭队列(通知所有通过Pop*阻塞的协程退出)

func (*Queue) Pop

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

从队头先进先出地从队列取出一项数据

func (*Queue) Push

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

将数据压入队列, 队尾

func (*Queue) Size

func (q *Queue) Size() int

获取当前队列大小

Jump to

Keyboard shortcuts

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