timer

package
v0.0.50-alpha.127 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timer provides a generic timer management system with multiple backend implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler[T any] func(ctx context.Context, item T) error

Handler processes items when their timer expires

type HandlerMap

type HandlerMap[T any] map[string]Handler[T]

HandlerMap maps timer types to their handlers

type KeyFunc

type KeyFunc[T any] func(item T) string

KeyFunc extracts a unique key from an item

type Manager

type Manager[T any] interface {
	// Register adds an item with a timeout duration for a specific type
	// If a timer with the same key already exists, it will be updated (upsert behavior)
	Register(ctx context.Context, timerType string, item T, timeout time.Duration) error

	// RegisterAt adds an item that expires at a specific time for a specific type
	RegisterAt(ctx context.Context, timerType string, item T, expireAt time.Time) error

	// RegisterIfNotExists adds an item with a timeout duration only if it doesn't exist
	// Returns false if timer already exists, true if newly registered
	RegisterIfNotExists(ctx context.Context, timerType string, item T, timeout time.Duration) (bool, error)

	// RegisterAtIfNotExists adds an item that expires at a specific time only if it doesn't exist
	// Returns false if timer already exists, true if newly registered
	RegisterAtIfNotExists(ctx context.Context, timerType string, item T, expireAt time.Time) (bool, error)

	// Cancel removes a timer for an item of a specific type
	Cancel(ctx context.Context, timerType string, key string) error

	// GetPending returns the count of pending timers for a specific type
	GetPending(ctx context.Context, timerType string) (int64, error)

	// Close releases resources and stops processing
	Close() error
}

Manager manages timers for items

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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