luci: go.chromium.org/luci/common/sync/promise Index | Files

package promise

import "go.chromium.org/luci/common/sync/promise"

Index

Package Files

map.go promise.go

Variables

var (
    // ErrNoData is an error returned when a request completes without available data.
    ErrNoData = errors.New("promise: No Data")
)

type Generator Uses

type Generator func(context.Context) (interface{}, error)

Generator is the Promise's generator type.

type Map Uses

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).

func (*Map) Get Uses

func (pm *Map) Get(c context.Context, key interface{}, gen Generator) *Promise

Get either returns an existing promise for the given key or creates and immediately launches a new promise.

type Promise Uses

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 multple 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 Uses

func New(c context.Context, gen Generator) *Promise

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 Uses

func NewDeferred(gen Generator) *Promise

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 Uses

func (p *Promise) Get(c context.Context) (interface{}, error)

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.

func (*Promise) Peek Uses

func (p *Promise) Peek() (interface{}, error)

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 2018-08-19. Refresh now. Tools for package owners.