timed

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 1 Imported by: 50

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Periodic

func Periodic(ctx canceler, period time.Duration, fn func() error) error

Periodic executes fn on every period. Periodic returns if the context is cancelled. The underlying ticket adjusts the intervals or drops ticks to make up for slow runs of fn. If fn is active, Periodic will only return when fn has finished. The period must be greater than 0, otherwise Periodic panics.

If fn returns an Error, then the loop is stopped and the functions error is returned directly. On normal termination the contexts reported error will be reported.

func Wait

func Wait(ctx canceler, duration time.Duration) error

Wait blocks for the configuration duration or until the passed context signal canceling. Wait return ctx.Err() if the context got cancelled early. If the duration has passed without the context being cancelled, Wait returns nil.

Example:

fmt.Printf("wait for 5 seconds...")
if err := Wait(ctx, 5 * time.Second); err != nil {
    fmt.Printf("shutting down")
    return err
}
fmt.Println("done")

Types

This section is empty.

Jump to

Keyboard shortcuts

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