10 namespace future {
namespace priv
12 template<
class R>
struct wrappedResult<SharedFuture<R>> {
typedef R type; };
16 unwrapOnReady(Promise<R>&& promise) : promise(move(promise)) {}
17 void operator()(StateBase& src)
19 if (src.ready) src.ex ? promise.setException(src.ex) : promise.setValue(
static_cast<State<R>&
>(src).result());
27 unwrapOnReady(Promise<void>&& promise) : promise(move(promise)) {}
28 void operator()(StateBase& src)
30 if (src.ready) src.ex ? promise.setException(src.ex) : promise.setValue();
33 Promise<void> promise;
40 class SharedFuture :
public FutureBase,
public FutureCommon<SharedFuture<R>, R>
49 typedef future::priv::State<R>
State;
60 ResultConstRef
get()
const;
77 if (_state->ex) _state->ex->raise();
78 return _state->result();
84 if (_state->ex) _state->ex->raise();
85 return _state->result();
92 if (_state->ex) _state->ex->raise();
98 if (_state->ex) _state->ex->raise();
102 template<class T, class R = typename std::decay<T>::type>
107 return promise.
future().share();
114 return promise.
future().share();
Unique future, guarantees sole access to a future function result.
Definition: Future.h:53
ResultConstRef get() const
Get the future result, waiting if necessary. Throws any exception stored in the result. The result can be retrieved repeatedly.
Definition: SharedFuture.h:74
State & __state() const
Get the shared state.
Definition: SharedFuture.h:64
Shared future, allows multiple access to a future function result.
Definition: Future.h:54
void delete_(T *&p)
Destruct object, free memory and set pointer to null.
Definition: Allocator.h:75
Future< R > future()
Get future from which delayed result can be retrieved.
Definition: Promise.h:207
SharedFuture(SharedFuture &&rhs)
Definition: SharedFuture.h:54
SharedFuture & operator=(SharedFuture &&rhs)
Definition: SharedFuture.h:57
Container to hold a delayed function result.
Definition: Promise.h:181
AllocatorObject< SmallAllocator > SmallAllocatorObject
Inherit from this class to use the small block allocator.
Definition: SmallAllocator.h:34
mt::disable_if< mt::True< T >::value &&(mt::isRef< R >::value||std::is_void< R >::value)>::type setValue(T &&val)
Set stored result. Result is copy/move constructed from value.
Definition: Promise.h:223
future::priv::State< R > State
Definition: SharedFuture.h:49
Mixin for common future methods.
Definition: Future.h:90
SharedFuture< R > SharedFutureCreate(T &&val)
Create a shared future that is immediately ready with the value.
Definition: SharedFuture.h:103
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
std::conditional< mt::isRef< R >::value||std::is_void< R >::value, R, typename mt::addConstRef< R >::type >::type ResultConstRef
Definition: SharedFuture.h:47
SharedFuture(const SharedFuture &rhs)
Definition: SharedFuture.h:53
future::priv::StateBase StateBase
Definition: Future.h:23
std::conditional< mt::isRef< R >::value||std::is_void< R >::value, R, typename mt::addRef< R >::type >::type ResultRef
Definition: SharedFuture.h:48
SharedFuture(Future< R > &&rhs)
Definition: SharedFuture.h:52
virtual StateBase * stateBase() const
Definition: SharedFuture.h:67
SharedFuture()
Definition: SharedFuture.h:51
Global Honeycomb namespace.
SharedFuture & operator=(const SharedFuture &rhs)
Definition: SharedFuture.h:56