SharedPromise provides the same interface as Promise, but you can extract multiple Futures from it, i.e. you can call getFuture() as many times as you'd like. When the SharedPromise is fulfilled, all of the Futures are completed. Calls to getFuture() after the SharedPromise is fulfilled return a completed Future. If you find yourself constructing collections of Promises and fulfilling them simultaneously with the same value, consider this utility instead. Likewise, if you find yourself in need of setting multiple callbacks on the same Future (which is indefinitely unsupported), consider refactoring to use SharedPromise to "split" the Future.
Declared in <folly/futures/SharedPromise.h>
template<class T>
class SharedPromise;
The SharedPromise must be kept alive manually. Consider FutureSplitter for automatic lifetime management.
| Name | Description |
|---|---|
getFuture | Return a Future tied to the shared core state. Unlike Promise::getFuture, this can be called an unlimited number of times per SharedPromise. NOTE: This function is deprecated. Please use getSemiFuture and pass the appropriate executor to .via on the returned SemiFuture to get a valid Future where necessary. |
getSemiFuture | Return a Future tied to the shared core state. Unlike Promise::getFuture, this can be called an unlimited number of times per SharedPromise. |
isFulfilled | Checks whether this SharedPromise has been fulfilled. |
setException | setException overloads |
setInterruptHandler | Set an interrupt handler to handle interrupts. See the documentation for Future::raise(). Your handler can do whatever it wants, but if you bother to set one then you probably will want to fulfill the SharedPromise with an exception (or special value) indicating how the interrupt was handled. |
setTry | Fulfill this SharedPromise with a Try, completing all associated futures. |
setValue | setValue overloads |
setWith | Fulfill this SharedPromise with the result of a function that takes no arguments and returns something implicitly convertible to T. Captures exceptions. e.g. |
size | Return the number of Futures associated with this SharedPromise |