ctxutil

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ctxutil provides context helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationWithJitter added in v1.1.0

func DurationWithJitter(cap time.Duration, attempt int64) time.Duration

DurationWithJitter returns an exponential backoff duration based on attempt with random "full jitter". https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

The maximum sleep is the cap. The minimum sleep is at least 3 milliseconds. Provided cap must be larger than minimum sleep, and attempt number must be a positive number.

func Sleep added in v0.7.0

func Sleep(ctx context.Context, d time.Duration)

Sleep pauses the current goroutine until d has passed or ctx is canceled.

func SleepWithJitter added in v1.1.0

func SleepWithJitter(ctx context.Context, d time.Duration, attempts int64)

SleepWithJitter pauses the current goroutine until d + jitter has passed or ctx is canceled.

func WithDelay

func WithDelay(done <-chan struct{}, delay time.Duration) (context.Context, context.CancelFunc)

WithDelay returns a context that is canceled after a given amount of time after done channel is closed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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