periodic

package
v4.45.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Periodic

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

Periodic holds a background goroutine that can do periodic work.

The work here cannot communicate errors directly, so it must communicate with channels or swallow errors.

NOTE: It's expected that Start and Stop are called on the same goroutine or be externally synchronized as to not race.

func New

func New(duration time.Duration, work func()) *Periodic

New creates new background work that runs every `duration` and performs `work`.

func NewWithContext

func NewWithContext(duration time.Duration, work func(context.Context)) *Periodic

NewWithContext creates new background work that runs every `duration` and performs `work`.

Work is passed a context that is cancelled when the overall periodic is cancelled.

func (*Periodic) Start

func (p *Periodic) Start()

Start starts the `Periodic` work.

It does not do work immedately, only after the time has passed.

func (*Periodic) Stop

func (p *Periodic) Stop()

Stop stops the periodic work and waits for the background goroutine to exit.

Jump to

Keyboard shortcuts

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