async

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](fns ...func() T) []T

All runs functions in parallel, waits for all

func AllWithError

func AllWithError[T any](fns ...func() (T, error)) ([]T, error)

AllWithError runs functions in parallel, returns first error

func ForEach

func ForEach[T any](items []T, concurrency int, fn func(T))

ForEach executes function for each item with concurrency limit

func Go

func Go(fn func())

Go executes function without waiting

func GoWithRecover

func GoWithRecover(fn func(), recoverFn func(any))

GoWithRecover executes with custom panic handler

func Map

func Map[T, R any](items []T, fn func(T) R) []R

Map transforms items in parallel

func SetPanicHandler

func SetPanicHandler(handler func(any))

SetPanicHandler sets a custom panic handler

Types

type Result

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

Result wraps an async operation's outcome

func NewResult

func NewResult[T any]() *Result[T]

NewResult creates a new Result

func Race

func Race[T any](fns ...func() T) *Result[T]

Race returns first completed result

func RaceWithTimeout

func RaceWithTimeout[T any](timeout time.Duration, fns ...func() T) *Result[T]

RaceWithTimeout returns first completed result or times out

func Run

func Run[T any](fn func() T) *Result[T]

Run executes function asynchronously

func RunWithContext

func RunWithContext[T any](ctx context.Context, fn func() T) *Result[T]

RunWithContext executes with context for cancellation

func RunWithTimeout

func RunWithTimeout[T any](timeout time.Duration, fn func() T) *Result[T]

RunWithTimeout executes with timeout

func (*Result[T]) Get

func (r *Result[T]) Get() (T, error)

Get blocks until result is ready

func (*Result[T]) GetOrDefault

func (r *Result[T]) GetOrDefault(defaultValue T) T

GetOrDefault returns the value or a default if there's an error

func (*Result[T]) Ready

func (r *Result[T]) Ready() bool

Ready checks if result is available (non-blocking)

func (*Result[T]) TimedOut

func (r *Result[T]) TimedOut() bool

TimedOut returns true if operation timed out

Jump to

Keyboard shortcuts

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