xtime

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package xtime contains extensions to the standard library package time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SleepContext

func SleepContext(ctx context.Context, d time.Duration) error

SleepContext pauses the current goroutine for at least the duration d and returns nil, unless ctx expires in the mean time in which case it returns ctx.Err().

A negative or zero duration causes SleepContext to return nil immediately.

If there is less than d left until ctx's deadline, returns DeadlineTooSoonError immediately.

Types

type DeadlineTooSoonError

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

func (DeadlineTooSoonError) Error

func (err DeadlineTooSoonError) Error() string

type JitterTicker added in v0.14.0

type JitterTicker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

A JitterTicker holds a channel that delivers "ticks" of a clock at intervals.

func NewJitterTicker added in v0.14.0

func NewJitterTicker(d time.Duration, jitter time.Duration) *JitterTicker

NewJitterTicker is similar to time.NewTicker, but jitters the ticks by the given amount. That is, each tick will be d+/-jitter apart.

The duration d must be greater than zero and jitter must be less than d; if not, NewJitterTicker will panic.

func (*JitterTicker) Reset added in v0.14.0

func (t *JitterTicker) Reset(d time.Duration, jitter time.Duration)

Reset stops the ticker and resets its period to be the specified duration and jitter. The next tick will arrive after the new period elapses.

The duration d must be greater than zero and jitter must be less than d; if not, Reset will panic.

func (*JitterTicker) Stop added in v0.14.0

func (t *JitterTicker) Stop()

Stop turns off the JitterTicker. After it returns, no more ticks will be sent. Stop does not close the channel, to prevent a concurrent goroutine reading from the channel from seeing an erroneous "tick".

Jump to

Keyboard shortcuts

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