Seastar
High performance C++ framework for concurrent servers
|
Like future except the result can be waited for by many fibers.
Represents a value which may not yet be ready. A fiber can wait for the value using the future obtained by calling get_future() or casting to future type. Multiple fibers are allowed to obtain a future for the result using the same instance of shared_future.
All futures obtained from shared_future should end up in the same state. However, if the value's copy constructor throws, some of the futures may end up in a failed state with an exception thrown from the copy constructor and end up with a state different than other futures.
The scope of shared_future instance doesn't have to include scopes of the futures obtained from that instance. In that sense the returned futures are independent.
shared_future can be copied at any time and all copies will resolve with the same value.
shared_future can be in a disengaged state when it's default-constructed or moved-from. When it's in such a state we say it's invalid and obtaining futures must not be attempted.
The types in the parameter pack T must all be copy-constructible.
When the first type in the parameter pack is with_clock then it has the effect of changing the clock used for timeouts by this instance. This type is omitted from the parameter of the future<> objects.
Example:
future<int> f; shared_future<with_clock<manual_clock>, int> sf(std::move(f)); future<int> f2 = sf;
#include <seastar/core/shared_future.hh>
Public Member Functions | |
shared_future (future_type f) | |
Forwards the result of future f into this shared_future. | |
shared_future (const shared_future &)=default | |
shared_future & | operator= (const shared_future &)=default |
shared_future (shared_future &&)=default | |
shared_future & | operator= (shared_future &&)=default |
future_type | get_future (time_point timeout=time_point::max()) const noexcept |
Creates a new future which will resolve with the result of this shared_future. More... | |
future_type | get_future (abort_source &as) const noexcept |
Creates a new future which will resolve with the result of this shared_future. More... | |
bool | available () const noexcept |
Returns true if the future is available (ready or failed) More... | |
bool | failed () const noexcept |
Returns true if the future is failed. More... | |
operator future_type () const noexcept | |
Equivalent to get_future() | |
bool | valid () const noexcept |
Returns true if the instance is in valid state. | |
|
inlinenoexcept |
Returns true if the future is available (ready or failed)
|
inlinenoexcept |
Returns true if the future is failed.
|
inlinenoexcept |
Creates a new future
which will resolve with the result of this shared_future.
as | abort source. The returned future will resolve with abort_requested_exception if this shared_future doesn't resolve before aborted. |
This object must be in a valid state.
|
inlinenoexcept |
Creates a new future
which will resolve with the result of this shared_future.
timeout | When engaged, the returned future will resolve with timed_out_error if this shared_future doesn't resolve before timeout is reached. |
This object must be in a valid state.