import "go.chromium.org/luci/common/sync/promise"
var ( // ErrNoData is an error returned when a request completes without available data. ErrNoData = errors.New("promise: No Data") )
Generator is the Promise's generator type.
type Map struct {
// contains filtered or unexported fields
}
Map is a map from some key to a promise that does something associated with this key.
First call to Get initiates a new promise. All subsequent calls return exact same promise (even if it has finished).
Get either returns an existing promise for the given key or creates and immediately launches a new promise.
type Promise struct {
// contains filtered or unexported fields
}
Promise is a promise structure with goroutine-safe methods that is responsible for owning a single piece of data. Promises have multiple readers and a single writer.
Readers will retrieve the Promise's data via Get(). If the data has not been populated, the reader will block pending the data. Once the data has been delivered, all readers will unblock and receive a reference to the Promise's data.
New instantiates a new, empty Promise instance. The Promise's value will be the value returned by the supplied generator function.
The generator will be invoked immediately in its own goroutine.
NewDeferred instantiates a new, empty Promise instance. The Promise's value will be the value returned by the supplied generator function.
Unlike New, the generator function will not be immediately executed. Instead, it will be run when the first call to Get is made, and will use one of the Get callers' goroutines. goroutine a Get caller.
Get returns the promise's value. If the value isn't set, Get will block until the value is available, following the Context's timeout parameters.
If the value is available, it will be returned with its error status. If the context times out or is cancelled, the appropriate context error will be returned.
Peek returns the promise's current value. If the value isn't set, Peek will return immediately with ErrNoData.
Package promise imports 3 packages (graph) and is imported by 4 packages. Updated 2021-01-20. Refresh now. Tools for package owners.