promise

package
v0.14.0-dev.6 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Promise

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

Promise is a simple implementation of a component that is represented eventual completion or failure of asynchronous operation and its resulting val

func New

func New[T any](execution func(resolve func(data T), reject func(err error))) *Promise[T]

New creates and returns a new Promise instance the execution function will be called in a separate goroutine and not block the caller's execution process, this function manages of execution flow and will decide based on its internal state which function should call The "resolve" function is invoked on success otherwise invokes a "reject"

func Then

func Then[T, M any](promise *Promise[T], resolveT func(T) M) *Promise[M]

Then wraps origin promise and use the resolver function to convert origin result value of type M into type T

func (*Promise[T]) Await

func (p *Promise[T]) Await() (T, error)

Await waits for execution to complete

Jump to

Keyboard shortcuts

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