gqueue
2 分钟阅读
原文:https://pkg.go.dev/github.com/gogf/gf/v2@v2.6.4/container/gqueue
Package gqueue provides dynamic/static concurrent-safe queue.
软件包 gqueue 提供动态/静态并发安全队列。
Features:
特征:
- FIFO queue(data -> list -> chan); FIFO 队列(数据 -> 列表 -> chan);
- Fast creation and initialization; 快速创建和初始化;
- Support dynamic queue size(unlimited queue size); 支持动态队列大小(无限队列大小);
- Blocking when reading data from queue; 从队列中读取数据时阻塞;
常量
This section is empty.
变量
This section is empty.
函数
This section is empty.
类型
type Queue
|
|
Queue is a concurrent-safe queue built on doubly linked list and channel.
队列是基于双链表和通道构建的并发安全队列。
func New
|
|
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.
New 返回一个空队列对象。可选参数 limit
用于限制队列的大小,默认情况下是无限的。当给定时 limit
,队列将是静态的和高性能的,这与 stdlib 通道相当。
Example
|
|
(*Queue) Close
|
|
Close closes the queue. Notice: It would notify all goroutines return immediately, which are being blocked reading using Pop method.
关闭 关闭队列。注意:它会立即通知所有 goroutines 返回,这些 goroutine 正在使用 Pop 方法阻止读取。
Example
|
|
(*Queue) Len
|
|
Len returns the length of the queue. Note that the result might not be accurate if using unlimited queue size as there’s an asynchronous channel reading the list constantly.
Len 返回队列的长度。请注意,如果使用无限的队列大小,则结果可能不准确,因为有一个异步通道不断读取列表。
Example
|
|
(*Queue) Pop
|
|
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.
Pop 以 FIFO 方式从队列中弹出一个项目。请注意,如果在队列关闭后调用 Pop,它将立即返回 nil。
Example
|
|
(*Queue) Push
|
|
Push pushes the data v
into the queue. Note that it would panic if Push is called after the queue is closed.
Push 将数据 v
推送到队列中。请注意,如果在队列关闭后调用 Push,则会出现恐慌。
Example
|
|
(*Queue) Size
|
|
Size is alias of Len. Deprecated: use Len instead.
size 是 Len 的别名。已弃用:请改用 Len。
Example
|
|