bqueue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 3 Imported by: 0

README

go-blocking-queue

A blocking queue based on go channel, supporting timeout and thread safe

Features

  • Blocking queue with timeout control
  • Minimalist API, based on channel, no other dependencies
  • Timeout control, reusing timer, reducing GC pressure under high concurrency
  • thread safe

Usage

Reference test cases.

Defects

  • Capacity must be specified, Unable to cope with scenarios where capacity cannot be estimated. Can be parameterized

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockQueue

type BlockQueue interface {
	/* Insert elements into the queue and block when the channel capacity is full. */
	Put(ele interface{}) bool

	/* Insert elements into the queue. When the channel capacity is full, it will block until timeout. */
	Offer(ele interface{}, timeout time.Duration) bool

	/* Get and remove the head element, when the channel is empty, it will block */
	Take() interface{}

	/* Get and remove the head element, when the channel is empty, it will block until timeout */
	Poll(timeout time.Duration) (interface{}, bool)

	/* queue len */
	Len() uint32

	/* queue capacity */
	Cap() uint32
}

func NewBlockingQueue

func NewBlockingQueue(capacity uint32) BlockQueue

Create and specify the capacity, which is actually the capacity of the channel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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