timermap

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

This file contains the timer manager struct and methods. A timer manager is used for handling a map of timers which perform a callback when they expire. They can be removed or renewed before they expire.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimerDoesNotExist = errors.New("timer does not exist")

Functions

This section is empty.

Types

type TimerMap

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

manager for a map of timers

func New

func New() (*TimerMap, func())

New initializes a new timer manager with the provided onTimeoutFunc.

Returns a pointer to TimerMap and a closer function.

func (*TimerMap) Add

func (m *TimerMap) Add(key string, onTimeout func(), timeout time.Duration)

Add creates and adds a timer to the map

func (*TimerMap) Remove

func (m *TimerMap) Remove(key string)

Remove removes a timer from the map

func (*TimerMap) Reset

func (m *TimerMap) Reset(key string, timeout time.Duration) (bool, error)

Reset resets a timer. It returns true if the timer was reset, false if the timer has already fired or has been stopped. If the timer does not exist, an error is also returned.

Jump to

Keyboard shortcuts

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