timeout

package
v0.0.0-...-a208e16 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2018 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NowMonotonic

func NowMonotonic() time.Time

NowMonotonic is like time.Now, but the result is monotonically increasing, and does not necessarily correspond to the actual current time.

Types

type Daemon

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

A Daemon is a handle on a daemon goroutine which allows for the scheduling and execution of timeouts and their related callbacks.

func NewDaemon

func NewDaemon(locker sync.Locker) *Daemon

NewDaemon starts a new daemon and returns a handle to it. A lock on locker will be acquired before any timeout's callback is executed.

func (*Daemon) AddTimeout

func (d *Daemon) AddTimeout(f func(), t time.Time) *Timeout

AddTimeout schedules f to be called at time t, which must be calculated relative to NowMonotonic (not time.Now). The returned *Timeout can be used to cancel the timeout, in which case f will not be called. It is guaranteed

that f will not be called before time t.

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop stops d.

type Timeout

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

A Timeout is a handle on a timeout which allows it to be cancelled.

func (*Timeout) Cancel

func (t *Timeout) Cancel()

Cancel cancels t. The caller must acquire a lock on the locker used to construct the related Daemon (in the call to NewDaemon) before calling Cancel. Otherwise, the behavior of Cancel is undefined.

Jump to

Keyboard shortcuts

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