xcall

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backoff added in v2.6.0

func Backoff(ctx context.Context, fn func(ctx context.Context, attempt int) (bool, error), retry int, baseDelay, maxDelay time.Duration) error

Backoff calls fn with an exponentially increasing delay.

The delay starts at baseDelay, doubles after every attempt and is capped at maxDelay. Retrying stops when fn returns next as false, when ctx is cancelled, or after retry attempts have been made. The attempt argument passed to fn starts at 1.

It returns the error of the last fn call, or ctx.Err() when ctx has been cancelled.

func Call

func Call[T funcType](fn T) error

Call invokes fn safely.

It recovers from any panic raised while fn runs: a runtime error (runtime.Error) is logged as a fatal error, while any other panic is logged together with its error message.

func Go added in v2.1.0

func Go[T funcType](fn T)

Go runs fn in a new goroutine.

fn is executed in its own goroutine and any panic is recovered by Call, so a crashing goroutine does not bring down the whole process.

func GoWithDeadline added in v2.2.3

func GoWithDeadline(deadline time.Time, fns ...func())

GoWithDeadline runs fns concurrently and blocks until all of them finish or the deadline is reached.

Unlike Go, it blocks the calling goroutine until every fn has completed or the deadline is reached, at which point it stops waiting.

func GoWithTimeout added in v2.2.3

func GoWithTimeout(timeout time.Duration, fns ...func())

GoWithTimeout runs fns concurrently and blocks until all of them finish or the timeout elapses.

Unlike Go, it blocks the calling goroutine until every fn has completed or the timeout is reached.

Types

type Goroutines added in v2.2.3

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

Goroutines is a goroutine group that manages a batch of functions to run concurrently.

func NewGoroutines added in v2.2.3

func NewGoroutines() *Goroutines

NewGoroutines returns a new Goroutines group.

func (*Goroutines) Add added in v2.2.3

func (g *Goroutines) Add(fns ...func()) *Goroutines

Add appends the given functions to the group and returns the group itself so that calls can be chained.

func (*Goroutines) Run added in v2.2.3

func (g *Goroutines) Run(ctx context.Context, timeout ...time.Duration)

Run starts every function the group holds, each in its own goroutine, and waits for them according to ctx.

The group is emptied before the functions run, so the same instance can be reused. When no timeout is given, Run blocks until all functions have finished; when a timeout is given, it returns early on timeout without waiting for the remaining functions.

Jump to

Keyboard shortcuts

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