timer

package
v0.0.50-alpha.103 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

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