ananb

package module
v0.0.0-...-807ed71 Latest Latest
Warning

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

Go to latest
Published: May 8, 2019 License: MIT Imports: 3 Imported by: 0

README

ananb

一个很简单的消息队列

快速入手

package main

import (
    "github.com/Justyer/ananb"
    "fmt"
)

func main() {
    tq := ananb.NewQueue().SetCap(100).Init()

    tq.Push([]byte{'hi'})
    task, _ := tq.Pop()
    fmt.Println(string(task))
}

方法

// 打入消息
Push([]byte) error

// 打入一堆消息
PushMany([][]byte) error

// 打入消息,如果队列满了会阻塞
MustPush([]byte)

// 打入一堆消息,如果队列满了会阻塞
MustPushMany([][]byte)

// 从队列中取一条消息, 如果数量不够则返回错误
Pop() ([]byte, error)

// 从队列中取一条消息, 如果mustGet为真时,即使数量不够也会取出,且不会报错,但剩余数量必须>0
PopMany(count int, mustGet bool) ([]byte, error)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrQueueFull is null
	ErrQueueFull = errors.New("queue has been full")
	//ErrQueueEmpty is null
	ErrQueueEmpty = errors.New("queue has no data")
)

Functions

This section is empty.

Types

type Queue

type Queue struct {
	Chl chan *qnode
	// contains filtered or unexported fields
}

Queue : ��任务队列

func NewQueue

func NewQueue() *Queue

NewQueue : 实例化一个任务队列

func (*Queue) Cap

func (q *Queue) Cap() int

Cap : 队列容量

func (*Queue) Init

func (q *Queue) Init() *Queue

Init : 初始化队列参数

func (*Queue) Len

func (q *Queue) Len() int

Len : 队列容量

func (*Queue) MustPush

func (q *Queue) MustPush(c []byte)

MustPush : 往队列中打入数据,如果队列满了则阻塞,直到队列中有空位

func (*Queue) MustPushMany

func (q *Queue) MustPushMany(cs [][]byte)

MustPushMany : 往队列中打入一批数据,如果队列满了则阻塞,直到队列中有空位

func (*Queue) Pop

func (q *Queue) Pop() ([]byte, error)

Pop : 从队列中取出数据

func (*Queue) PopMany

func (q *Queue) PopMany(count int, mustGet bool) ([][]byte, error)

PopMany : 从队列中取出多个数据

func (*Queue) Push

func (q *Queue) Push(c []byte) error

Push : 往队列中打入数据

func (*Queue) PushMany

func (q *Queue) PushMany(cs [][]byte) error

PushMany : 往队列中打入一批数据

func (*Queue) SetCap

func (q *Queue) SetCap(cap int) *Queue

SetCap : 设置队列最大长度

Jump to

Keyboard shortcuts

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