go-async
Library that provides promise-like functionality for running functions asynchronously.
Usage
Imagine a function that takes some time to complete.
And we want to run it asynchronously and later take the results.
f := func() (string, error) {
time.Sleep(time.Second)
return "Hello world", nil
}
- Start a function and save the promise (under the hood it runs in a separate goroutine):
promise := async.RunVE(f)
- Wait for results:
value, err := promise.Wait()
Naming
RunVE
means we run function that returns Value and Error.
Supported functions described here. Each function type has its own Run*
method.