timeout

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 3 Imported by: 0

README

timeout

Go Reference

a library that implements some common timeout mechanisms with generics

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChannelClosed = errors.New("channel is closed")

Functions

func Chan

func Chan[T any](
	ctx context.Context,
	d time.Duration,
	c <-chan T,
) (T, error)

Chan listens for a message from c. If d expires before receiving a message from c, context.DeadlineExceeded is returned. If ctx is cancelled before receiving a message from c, the cancellation cause is returned. If c is closed before receiving a message from c, ErrChannelClosed is returned.

func Context

func Context(
	ctx context.Context,
	d time.Duration,
) (context.Context, *time.Timer)

Context creates a child context of ctx that will be cancelled after d. It also returns the timer that will issue the cancellation so that the cancellation of the returned context can be prevented.

func Func

func Func[T any](
	ctx context.Context,
	d time.Duration,
	fn func(context.Context) (T, error),
) (T, error)

Func runs fn with a context that is canceled with context.DeadlineExceeded if fn does not return within the duration specified by d. This function is not guaranteed to return within the specified duration because it allows fn to handle cancellation gracefully.

Types

This section is empty.

Jump to

Keyboard shortcuts

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