Seastar
High performance C++ framework for concurrent servers
Public Types | Public Member Functions | List of all members
seastar::shared_future< T > Class Template Reference

Detailed Description

template<typename... T>
class seastar::shared_future< T >

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 <shared_future.hh>

Public Types

using clock = typename options::clock_type
 
using time_point = typename clock::time_point
 
using future_type = typename future_option_traits< T... >::template parametrize< future >::type
 
using promise_type = typename future_option_traits< T... >::template parametrize< promise >::type
 
using value_tuple_type = typename future_option_traits< T... >::template parametrize< std::tuple >::type
 

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_futureoperator= (const shared_future &)=default
 
 shared_future (shared_future &&)=default
 
shared_futureoperator= (shared_future &&)=default
 
future_type get_future (time_point timeout=time_point::max()) const
 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
 Equivalent to get_future()
 
bool valid () const
 Returns true if the instance is in valid state.
 

Member Function Documentation

◆ available()

template<typename... T>
bool seastar::shared_future< T >::available ( ) const
inlinenoexcept

Returns true if the future is available (ready or failed)

Note
This object must be in a valid state.

◆ failed()

template<typename... T>
bool seastar::shared_future< T >::failed ( ) const
inlinenoexcept

Returns true if the future is failed.

Note
This object must be in a valid state.

◆ get_future()

template<typename... T>
future_type seastar::shared_future< T >::get_future ( time_point  timeout = time_point::max()) const
inline

Creates a new future which will resolve with the result of this shared_future.

Parameters
timeoutWhen 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.


The documentation for this class was generated from the following files: