Source File
future.go
Belonging Package
github.com/alitto/pond/v2/internal/future
package futureimport ()type FutureResolver func(err error)// A Future represents a value that will be available in the Future.// It is always associated with a context that can be used to wait for the value to be available.// When the parent context is canceled, the Future will be canceled as well.type Future struct {ctx context.Context}func ( *Future) () <-chan struct{} {return .ctx.Done()}func ( *Future) () error {<-.ctx.Done():= context.Cause(.ctx)if != nil {if , := .(*futureResolution); {return .err}}return}// Wait waits for the future to complete and returns any error that occurred.func ( *Future) () error {return .Err()}func ( context.Context) (*Future, FutureResolver) {, := context.WithCancelCause():= &Future{ctx: ,}return , func( error) {(&futureResolution{err: ,})}}type futureResolution struct {err error}func ( *futureResolution) () string {if .err != nil {return .err.Error()}return "future resolved"}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |