periodic

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: GPL-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures Start.

func Immediate

func Immediate() Option

Immediate starts the periodic task immediately instead of after the first tick.

func OnStop

func OnStop(f func(Tick)) Option

OnStop configures a callback that is executed when a periodic task is stopped or canceled.

type Stopper

type Stopper interface {
	Stop() // Stops a periodic task.
}

Stopper implements the Stop method, which stops a periodic task from Start().

func Start

func Start(ctx context.Context, interval time.Duration, callback func(Tick), options ...Option) Stopper

Start starts a periodic task with a ticker at the specified interval, which executes the given callback after each tick. Pending tasks do not overlap, but could start immediately if the previous task(s) takes longer than the interval. Call Stop() on the return value in order to stop the ticker and to release associated resources. The interval must be greater than zero.

type Tick

type Tick struct {
	Elapsed time.Duration
	Time    time.Time
}

Tick is the value for periodic task callbacks that contains the time of the tick and the time elapsed since the start of the periodic task.

Jump to

Keyboard shortcuts

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