race

package
v1.104.7 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 3 Imported by: 3 modules, 1 package

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 race contains a helper to "race" two functions, returning the first successful result. It also allows explicitly triggering the (possibly-waiting) second function when the first function returns an error or indicates that it should be retried.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func[T any] func(context.Context) (T, error)

Func is the signature of a function to be called.

type Race

type Race[T any] struct {
	// contains filtered or unexported fields
}

Race allows running two functions concurrently and returning the first non-error result returned.

func New

func New[T any](d time.Duration, func1, func2 Func[T]) *Race[T]

New creates a new Race that, when Start is called, will immediately call func1 to obtain a result. After the timeout d or if triggered by an error response from func1, func2 will be called.

func (*Race[T]) Start

func (rh *Race[T]) Start(ctx context.Context) (T, error)

Start will start the "race" process, returning the first non-error result or the errors that occurred when calling func1 and/or func2.

Jump to

Keyboard shortcuts

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