async

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package async provides a simple way to run functions asynchronously.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await[T any](f *Future[T]) (T, error)

Await waits for the future to resolve and returns the value.

Types

type Future

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

Future is a type that represents a future value.

func All added in v0.1.7

func All[T any](futures ...*Future[T]) *Future[[]T]

All returns a future that resolves when all the provided futures resolve.

func New

func New[T any](fn func() (T, error)) *Future[T]

New returns a new future.

func (*Future[T]) Await

func (f *Future[T]) Await() (T, error)

Await waits for the future to resolve and returns the value.

func (*Future[T]) Catch

func (f *Future[T]) Catch(fn func(error)) *Future[T]

Catch sets a callback to be called when the future rejects.

func (*Future[T]) MarshalJSON

func (f *Future[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Future[T]) Then

func (f *Future[T]) Then(fn func(T)) *Future[T]

Then sets a callback to be called when the future resolves.

func (*Future[T]) UnmarshalJSON

func (f *Future[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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