Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIncomplete is returned when GetNow is invoked and the Func associated with the Promise hasn't completed. ErrIncomplete = errors.New("incomplete") )
Functions ¶
Types ¶
type Func ¶
Func represents any function that returns a Promise when passed to Run or Then.
func WithCancellation ¶
WithCancellation takes in a Func and returns a Func that implements the passed-in Func's behavior, but adds context cancellation.
type Promise ¶
type Promise[V any] struct { // contains filtered or unexported fields }
Promise represents a potential or actual result from running a Func.
func Run ¶
Run produces a Promise for the supplied Func, evaluating the supplied context.Context and data. The Promise is returned immediately, no matter how long it takes for the Func to complete processing.
func Then ¶
Then produces a Promise for the supplied Func, evaluating the supplied context.Context and Promise. The returned Promise is returned immediately, no matter how long it takes for the Func to complete processing. If the supplied Promise returns a non-nil error, the error is propagated to the returned Promise and the passed-in Func is not run.
func (*Promise[V]) Get ¶
Get returns the value and the error (if any) for the Promise. Get waits until the Func associated with this Promise has completed. If the Func has completed, Get returns immediately.
type PromiseSet ¶
PromiseSet a struct holding a list of promises
func NewPromiseSet ¶
func NewPromiseSet[V any]() *PromiseSet[V]
NewPromiseSet make a new promise set with an initialized promises slice
func (*PromiseSet[V]) Add ¶
func (promiseSet *PromiseSet[V]) Add(promises ...*Promise[V])
Add add one or more promises to promise set
func (*PromiseSet[V]) Wait ¶
func (promiseSet *PromiseSet[V]) Wait() error
Wait wait for all promises in promiseset to complete. Same as the Wait function but tied to a promise set