delayqueue

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package delayqueue describe an delayqueue implemention.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelayQueue

type DelayQueue[T any] interface {
	// Offer insert the element into the current DelayQueue,
	// if the expiration is blow the current min expiration, the item will
	// been fired first.
	Offer(elem T, expireation int64)

	// Poll starts an infinite loop, it will continually waits for an element to
	// been fired, and send the element to the output Chan.
	Poll(ctx context.Context)

	// Chan return the output chan, when the element is fired the element
	// will send to the channel.
	Chan() <-chan T

	// Size return the element count in the queue
	Size() int
}

DelayQueue is an blocking queue of *Delay* elements, the element can only been taken when its delay has expired. The head of the queue is the element whose delay expired most recent in the queue.

func New

func New[T any](size int) DelayQueue[T]

New construct a DelayQueue with the initial size

func NewWithTimer

func NewWithTimer[T any](size int, t Timer) DelayQueue[T]

NewWithTimer construct a DelayQueue with the initial size and Timer

type Timer

type Timer interface {
	Now() int64
}

Timer for provide the current ms

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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