timer

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const Forever = -1

Variables

This section is empty.

Functions

func ClearInterval

func ClearInterval(id ID)

ClearTimeout removes the interval timer by ID

func ClearTimeout

func ClearTimeout(id ID)

ClearTimeout removes the timeout timer by ID

Types

type ID

type ID int64

ID represents ID of timer task

func SetInterval

func SetInterval(d time.Duration, task Task) ID

SetInterval add interval timer

func SetIntervalFunc

func SetIntervalFunc(d time.Duration, fn TaskFunc) ID

SetIntervalFunc add a interval timer func

func SetTimeout

func SetTimeout(d time.Duration, task Task) ID

SetTimeout add a timeout timer

func SetTimeoutFunc

func SetTimeoutFunc(d time.Duration, fn TaskFunc) ID

SetTimeoutFunc add a timeout timer func

func (ID) Valid

func (id ID) Valid() bool

type Scheduler

type Scheduler interface {
	// Start starts the Scheduler
	Start() error
	// Shutdown shutdowns the Scheduler
	Shutdown()
	// Add adds a new timer task
	Add(next, duration time.Duration, task Task, times int) ID
	// Remove removes a timer task by ID
	Remove(id ID)
}

Scheduler schedules timers

func NewMemoryScheduler

func NewMemoryScheduler() Scheduler

NewMemoryScheduler creates in-memory Scheduler

type Task

type Task interface {
	ExecTimer(ID)
}

Task represents timer task

type TaskFunc

type TaskFunc func(ID)

TaskFunc wraps function as a task

func (TaskFunc) ExecTimer

func (fn TaskFunc) ExecTimer(id ID)

ExecTimer implements Task ExecTimer method

type Ticker added in v0.0.18

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

func NewTicker added in v0.0.18

func NewTicker(interval time.Duration) *Ticker

func (*Ticker) Interval added in v0.0.18

func (t *Ticker) Interval() time.Duration

func (*Ticker) Next added in v0.0.18

func (t *Ticker) Next(now time.Time) bool

Jump to

Keyboard shortcuts

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