Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Promise ¶
type Promise[T any] interface { // Await returns the result of the async operation. // If the operation has not completed it will block // until it does complete. // Otherwise it will return the result of the operation // immediately. Await() (T, error) // AwaitOr returns the result of the async operation // or a default value if the operation was not successful. AwaitOr(defaultValue T) T // Then executes the given functions when the promise // is either fulfilled or rejected respectively. // The functions are executed in a goroutine. Then(func(T), func(error)) // OnSuccess executes the given function if the // promise is fulfilled. // The functions is executed in a goroutine. OnSuccess(func(T)) // OnFailure executes the given function if the // promise is rejected. // The functions is executed in a goroutine. OnFailure(func(error)) // Done returns a channel that's closed when the work done on behalf of this // promise is finished. Successive calls to Done return the same value. // The close of the Done channel may happen asynchronously, // after the function returns. // // Done is provided for use in select statements: // // // Produce generates a value by awaiting the promise and sending it to the out // // channel. It returns an error if the promise returned an error or ctx.Done is closed. // func Produce(ctx context.Context, p Promise[Value], out chan<- Value) error { // for { // select { // case <-ctx.Done(): // return ctx.Err() // case <-p.Done(): // v, err := p.Await() // returns immediately since the promise is already resolved // if err != nil { // return err // } // out <- v // } // } // } Done() <-chan struct{} }
Promise is a object that can be used to get the result of an async operation.
func All ¶ added in v0.2.0
All takes multiple promises and returns a single promise, which will resolve to a slice of all the results of the promises.
If any of the promises fail, the returned promise will fail as well and contain the first error which occurred.
Click to show internal directories.
Click to hide internal directories.