notify

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Notify

func Notify(cond Condition, interval time.Duration, countdown ...time.Duration) (closeFunc func())

Notify is a convenience function that initializes a new Notifier with the given condition, interval, and countdown. It is the responsibility of the caller to call close to stop polling.

Types

type Condition

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

Condition is a function that gets executed with a certain time.

  • It should return the deadline for the notification, as well as a callback function to execute once the time to the deadline is less than one of the notify attempts. 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 calls a Condition at most once for each count in countdown.

func New

func New(cond Condition, countdown ...time.Duration) *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 added in v0.8.2

func (n *Notifier) Close() error

func (*Notifier) Poll

func (n *Notifier) Poll(ticker <-chan time.Time)

Poll polls once immediately, and then once for every value from ticker. Poll exits when ticker is closed.

Jump to

Keyboard shortcuts

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