clock

package
v0.0.0-...-466b026 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clock provides clocks, timers and timing helpers for network I/O.

Index

Constants

This section is empty.

Variables

View Source
var Past = time.Unix(1, 0)

Past is a deadline long passed, which interrupts blocked I/O.

View Source
var RealEpoch = NewEpoch(nil)

RealEpoch is the epoch of the system clock that components without a clock of their own share; it is the one time base of activity tracking on the system clock.

Functions

func IsClosed

func IsClosed(c <-chan struct{}) bool

IsClosed reports whether c is closed.

Types

type Backoff

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

Backoff spaces out the retries of a loop whose calls fail, such as the reads of a listener's socket or an Accept: the first failure is retried at once, as a single error such as an ICMP report or an aborted connection concerns that call alone, and failures that persist are retried with a delay that doubles from 1ms up to 1s. Its zero value is ready.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset starts over after a success.

func (*Backoff) Wait

func (b *Backoff) Wait(done <-chan struct{}) bool

Wait waits before the retry of a failure and reports whether it did, rather than see done closed first.

type Deadline

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

Deadline is a resettable deadline whose expiry closes a channel, as in net.Pipe. Its zero value is not usable; see MakeDeadline.

func MakeDeadline

func MakeDeadline() Deadline

MakeDeadline returns a deadline that is not set.

func (*Deadline) Set

func (d *Deadline) Set(t time.Time)

Set makes the deadline expire at t, or never for the zero t. A wait on the channel of an earlier Wait goes on unless t has passed.

func (*Deadline) Stop

func (d *Deadline) Stop()

Stop releases the pending timer, if any, without changing whether the deadline has expired, and keeps later calls of Set from starting another.

func (*Deadline) Wait

func (d *Deadline) Wait() <-chan struct{}

Wait returns a channel that is closed once the deadline has expired.

type Epoch

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

Epoch tells the time of a clock as nanoseconds since the clock's time when the Epoch was made, for activity tracking in atomics. Each component takes the epoch of the clock it is given, so that a clock of any time, such as a fake one at the zero time, counts right, and a step of the system's wall clock neither stretches nor cuts an idle period.

func NewEpoch

func NewEpoch(c timeshim.Clock) *Epoch

NewEpoch returns the epoch of c, or of the system clock when c is nil, at its time now.

func (*Epoch) At

func (e *Epoch) At(t time.Time) int64

At returns t, a time of the clock, as nanoseconds since the epoch.

func (*Epoch) Clock

func (e *Epoch) Clock() timeshim.Clock

Clock returns the clock of e.

func (*Epoch) Now

func (e *Epoch) Now() int64

Now returns the clock's time as nanoseconds since the epoch.

func (*Epoch) Touch

func (e *Epoch) Touch(last *atomic.Int64)

Touch advances last to the current epoch time.

type Idle

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

Idle runs a callback once activity has stopped for a given duration. After Init, its other methods are safe to call concurrently.

func (*Idle) BeginWait

func (i *Idle) BeginWait()

BeginWait begins an operation during which the timer must not expire.

func (*Idle) End

func (i *Idle) End()

End disarms the timer and prevents Start from arming it again. A callback that has already expired may still run.

func (*Idle) EndWait

func (i *Idle) EndWait()

EndWait ends one operation started by BeginWait and records activity.

func (*Idle) Init

func (i *Idle) Init(d time.Duration, c timeshim.Clock)

Init sets up a zero Idle with timeout d, which must be positive. Call Start to arm it.

func (*Idle) Start

func (i *Idle) Start(expire func())

Start arms the timer on its first call. Later calls and calls after End have no effect. On expiry it calls expire outside the lock.

func (*Idle) Touch

func (i *Idle) Touch()

Touch records activity.

Jump to

Keyboard shortcuts

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