12 template<
class R,
class... Param>
21 template<
class F,
class Alloc>
22 PackagedTask(F&& f, Alloc&& a) : _func(
std::allocator_arg_t(), a, forward<F>(f)), _promise(a), _invoked(false) {}
38 template<
class... Args>
39 void operator()(Args&&... args) { invoke(
true, forward<Args>(args)...); }
41 template<
class... Args>
53 promise._state->setReady();
56 _promise._state->setReady();
60 bool valid()
const {
return _promise.valid(); }
65 function<R (Param...)>&
getFunc() {
return _func; }
68 void setFunc(F&& f) { _func = forward<F>(f); }
71 template<
class F,
class Alloc>
73 _func(
std::allocator_arg_t(), forward<Alloc>(a), forward<F>(f)), _promise(move(promise)), _invoked(false) {}
75 template<
class... Args>
76 void invoke(
bool setReady, Args&&... args)
78 if (!valid())
throw_ future::NoState();
79 if (_invoked)
throw_ future::AlreadySatisfied();
81 future::priv::invoke<R>()(*_promise._state, setReady, _func, forward<Args>(args)...);
84 function<R (Param...)> _func;
void setReady(bool reset=false)
Signal to future that result is ready for retrieval, and optionally reset task before signalling...
Definition: PackagedTask.h:45
function< R(Param...)> & getFunc()
Get function that will be invoked.
Definition: PackagedTask.h:65
Unique future, guarantees sole access to a future function result.
Definition: Future.h:53
PackagedTask & operator=(PackagedTask &&rhs)
Definition: PackagedTask.h:25
void setFunc(F &&f)
Set function to be invoked.
Definition: PackagedTask.h:68
void reset()
Reset the task so it can be invoked again, a new future is created for the next result.
Definition: PackagedTask.h:62
Inherit to declare that class is not copyable.
Definition: Meta.h:286
PackagedTask(PackagedTask &&rhs) noexcept
Definition: PackagedTask.h:23
PackagedTask(F &&f, Alloc &&a)
Definition: PackagedTask.h:22
Container to hold a delayed function result.
Definition: Promise.h:181
Mixin for common future methods.
Definition: Future.h:90
auto reset()
Reset bytestream manipulator state.
Definition: ByteStream.h:417
PackagedTask(F &&f)
Definition: PackagedTask.h:20
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
A container that wraps a function so that its result is stored in a future when invoked.
Definition: PackagedTask.h:10
Future< R > future()
Get future from which delayed result can be retrieved.
Definition: PackagedTask.h:31
#define throw_
Use in place of throw keyword to throw a honey::Exception object polymorphically and provide debug in...
Definition: Exception.h:11
void invoke_delayedReady(Args &&...args)
Same as operator() except don't make future ready. User is responsible to call setReady() afterwards...
Definition: PackagedTask.h:42
bool valid() const
Check if this instance has state and can be used. State can be transferred out to another instance th...
Definition: PackagedTask.h:60
PackagedTask()
Definition: PackagedTask.h:18
void operator()(Args &&...args)
Invoke stored function to evaluate result for associated future.
Definition: PackagedTask.h:39
Global Honeycomb namespace.