util

package
v0.0.0-...-214a605 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString convert []byte type to string type

func GetUUID

func GetUUID() uint64

GetUUID 使用默认的uuidWorker生成一个uuid

func NewUUIDWorker

func NewUUIDWorker(workerID int64) (*uuidWorker, error)

NewUUIDWorker 指定一个节点id,返回该节点对应的uuid生成器 使用多个uuidWorker时,id由调用者保证不重复

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes convert string type to []byte type

func WriteFull

func WriteFull(writer io.Writer, data []byte) error

WriteFull往指定writer中写数据,知道数据完全写入或者发生错误

Types

type MsgQueue

type MsgQueue struct {
	// contains filtered or unexported fields
}

MsgQueue 是一个双缓冲队列的BlockingQueue 在"多生产者,单消费者"的场景下下保证线程安全

func NewMsgQueue

func NewMsgQueue() *MsgQueue

NewMsgQueue 创建并返回一个初始容量为0的消息队列

func NewMsgQueueWithCap

func NewMsgQueueWithCap(cap int) *MsgQueue

NewMsgQueueWithCap 创建并返回一个指定初始容量的消息队列

func (*MsgQueue) Pick

func (q *MsgQueue) Pick(retList *[]interface{})

Pick 获取当前队列中的所有元素,若当前队列为空,则阻塞直至有新元素被添加

func (*MsgQueue) PickWithCtx

func (q *MsgQueue) PickWithCtx(ctx context.Context, retList *[]interface{})

PickWithCtx 与Pick相同,但当ctx active时,强制退出阻塞状态并返回

func (*MsgQueue) PickWithSignal

func (q *MsgQueue) PickWithSignal(signal <-chan struct{}, retList *[]interface{})

PickWithSignal 与Pick相同,但当signal active时,强制退出阻塞状态并返回

func (*MsgQueue) Put

func (q *MsgQueue) Put(msg interface{})

Put 往队列中添加元素

Jump to

Keyboard shortcuts

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