Thanks to visit codestin.com
Credit goes to pkg.go.dev

notify

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition func(now time.Time) (deadline time.Time, callback func())

Condition is a function that gets executed periodically, and receives the current time as an argument.

  • It should return the deadline for the notification, as well as a callback function to execute. If deadline is the zero time, callback will not be executed.
  • Callback is executed once for every time the difference between deadline and the current time is less than an element of countdown.
  • To enforce a minimum interval between consecutive callbacks, truncate the returned deadline to the minimum interval.

type Notifier

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

Notifier triggers callbacks at given intervals until some event happens. The intervals (e.g. 10 minute warning, 5 minute warning) are given in the countdown. The Notifier periodically polls the condition to get the time of the event (the Condition's deadline) and the callback. The callback is called at most once per entry in the countdown, the first time the time to the deadline is shorter than the duration.

func New

func New(cond Condition, interval time.Duration, countdown []time.Duration, opts ...Option) *Notifier

New returns a Notifier that calls cond once every time it polls.

  • Duplicate values are removed from countdown, and it is sorted in descending order.

func (*Notifier) Close

func (n *Notifier) Close()

type Option added in v2.13.0

type Option func(*Notifier)

func WithTestClock added in v2.13.0

func WithTestClock(clk quartz.Clock) Option

WithTestClock is used in tests to inject a mock Clock

Jump to

Keyboard shortcuts

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