Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoData is an error returned when a request completes without available data. ErrNoData = errors.New("promise: No Data") )
Functions ¶
This section is empty.
Types ¶
type Map ¶
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).
type 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.
func New ¶
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.
func NewDeferred ¶
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.
func (*Promise) Get ¶
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.