folly::coro::SharedPromise

SharedPromise is a simple wrapper around folly::coro::Promise and folly::coro::Future that allows for fetching cancellable and awaitable futures from a single promise.

Synopsis

Declared in <folly/coro/SharedPromise.h>

template<typename T>
class SharedPromise;

Description

It has the same behavior as folly::SharedPromise<>. This includes the difference in behavior of folly::SharedPromise and folly::Promise with regards to invalid promise exceptions -- when SharedPromise<> is moved from, calling setValue(), setTry(), or setException() don't result in a PromiseInvalid exception.

Member Functions

NameDescription
SharedPromise [constructor]Constructors
operator= Assignment operators
getFuture Returns a future that is fulfilled when the user sets a value on the promise. Because this is a coro::Future, it supports cancellation.
isFulfilled Returns true if the promise has either a value or an exception set.
poll Returns either an optional holding the result or an empty optional depending on whether or not (respectively) the promise has been fulfilled (i.e., isFulfilled() == true).
setException Sets an exception in the promise.
setTry Sets a folly::Try object in the promise.
setValue setValue overloads
size Returns the number of futures associated with the SharedPromise.