timer

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const Forever = -1

Forever

Variables

This section is empty.

Functions

func ClearInterval

func ClearInterval(scheduler Scheduler, id ID)

ClearTimeout removes the interval timer by ID

func ClearTimeout

func ClearTimeout(scheduler Scheduler, 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(scheduler Scheduler, d time.Duration, task Task) ID

SetInterval add interval timer

func SetIntervalFunc

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

SetIntervalFunc add a interval timer func

func SetTimeout

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

SetTimeout add a timeout timer

func SetTimeoutFunc

func SetTimeoutFunc(scheduler Scheduler, 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()
	// 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 {
	Exec(ID)
}

Task represents timer task

type TaskFunc

type TaskFunc func(ID)

TaskFunc wraps function as a task

func (TaskFunc) Exec added in v0.3.5

func (fn TaskFunc) Exec(id ID)

Exec implements Task Exec 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