timerqueue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: MIT Imports: 2 Imported by: 6

README

Timer Queue for Go

A Go package providing timer queue for a list of items that should be processed in at a fixed duration of time after being added.

License MIT GoDoc

Installation

go get github.com/jirenius/timerqueue

Documentation

Overview

Package timerqueue provides a timer queue for a list of items that should be processed after a fixed duration of time from when they are added to the queue. All operations are safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue holds a list of elements. When a new element is added to the queue, the queue callback will be called with the element after the set queue duration.

func New

func New(callback func(interface{}), duration time.Duration) *Queue

New creates a new timer Queue

func (*Queue) Add

func (q *Queue) Add(v interface{})

Add adds a new element to the timer Queue, starting a timer for the fixed duration for the queue. Once the duration has passed, the queue callback will be called.

func (*Queue) Clear

func (q *Queue) Clear() []interface{}

Clear removes all elements from the queue. Returns a slice of the elements cleared from the queue.

func (*Queue) Flush

func (q *Queue) Flush()

Flush calls the callback for each element in the queue. Any new element added while flushing, will not be called.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of elements in the queue

func (*Queue) Remove

func (q *Queue) Remove(v interface{}) bool

Remove removes an element from the queue. Returns false if the element was not in the queue, otherwise true.

func (*Queue) Reset

func (q *Queue) Reset(v interface{}) bool

Reset sets the time of the element callback back to full duration. Returns false if the the element was not in the queue, otherwise true.

Jump to

Keyboard shortcuts

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