timer

package
v0.0.11-otel Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package timer defines the interface for timer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpType

type OpType string

OpType specifies one handler.

type OperationItem

type OperationItem[T comparable] struct {
	// OpType specifies the operation type.
	OpType OpType

	// ID specifies the task unique id.
	ID T

	// RunTime specifies the task run time.
	RunTime time.Time
}

OperationItem specifies one task in timer.

type Operator

type Operator[T comparable] interface {
	// Start starts the timer
	Start()

	// Stop stops the timer
	Stop()

	// Register binds a handler for one operation type.
	// This function should be invoked before all Add.
	Register(opType OpType, handler func(id T))

	// Add adds a new task to timer.
	Add(opType OpType, id T, delay time.Duration) error

	// Get gets the task from timer.
	Get(opType OpType, id T) *OperationItem[T]

	// GetAll gets all active tasks from timer.
	GetAll() []*OperationItem[T]

	// Remove removes the task from timer.
	Remove(opType OpType, id T) error
}

Operator is the interface for timer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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