BitShares-Core
7.0.2
BitShares blockchain node software and command-line wallet software
|
Go to the documentation of this file.
11 #ifdef FC_TASK_NAMES_ARE_MANDATORY
12 # define FC_TASK_NAME_DEFAULT_ARG
14 # define FC_TASK_NAME_DEFAULT_ARG = "?"
18 #ifdef FC_CANCELATION_REASONS_ARE_MANDATORY
19 # define FC_CANCELATION_REASON_DEFAULT_ARG
21 # define FC_CANCELATION_REASON_DEFAULT_ARG = nullptr
36 template<
typename Functor,
typename T>
43 _func( *
static_cast<const T*
>(v), e);
48 template<
typename Functor>
61 class promise_base :
public std::enable_shared_from_this<promise_base> {
63 typedef std::shared_ptr<promise_base>
ptr;
86 void _enqueue_thread();
87 void _dequeue_thread();
93 std::atomic<bool> _ready;
94 std::atomic<thread*> _blocked_thread;
95 std::atomic<int32_t> _blocked_fiber_count;
105 std::atomic<detail::completion_handler*> _compl;
108 template<
typename T =
void>
111 typedef std::shared_ptr< promise<T> >
ptr;
128 this->
_wait( timeout );
146 template<
typename CompletionHandler>
161 typedef std::shared_ptr< promise<void> >
ptr;
175 this->
_wait( timeout );
184 template<
typename CompletionHandler>
219 std::swap(m_prom,f.m_prom);
223 operator const T&()
const {
return wait(); }
229 return m_prom->wait(timeout);
237 return m_prom->wait_until(tp);
240 bool valid()
const {
return !!m_prom; }
243 bool ready()
const {
return m_prom->ready(); }
246 bool error()
const {
return m_prom->error(); }
249 bool canceled()
const {
if( m_prom )
return m_prom->canceled();
else return true;}
260 catch (
const canceled_exception&)
273 template<
typename CompletionHandler>
275 m_prom->on_complete( std::forward<CompletionHandler>(c) );
291 std::swap(m_prom,f.m_prom);
301 m_prom->wait(timeout);
308 m_prom->wait_until(tp);
311 bool valid()
const {
return !!m_prom; }
312 bool canceled()
const {
return m_prom ? m_prom->canceled() :
true; }
321 catch (
const canceled_exception&)
327 bool ready()
const {
return m_prom->ready(); }
330 bool error()
const {
return m_prom->error(); }
334 template<
typename CompletionHandler>
336 m_prom->on_complete( std::forward<CompletionHandler>(c) );
void on_complete(CompletionHandler &&c)
const char * _cancellation_reason
completion_handler_impl(Functor &&f)
void cancel(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG) const
a placeholder for the result of an asynchronous operation.
completion_handler_impl(const Functor &f)
std::shared_ptr< promise< T > > ptr
void wait_until(const time_point &tp)
const T & wait(const microseconds &timeout=microseconds::maximum())
virtual void on_complete(const void *v, const fc::exception_ptr &e)
completion_handler_impl(Functor &&f)
promise_base(const char *desc FC_TASK_NAME_DEFAULT_ARG)
void set_value(const void_t &)
virtual void on_complete(const void *v, const fc::exception_ptr &e)
future(const typename promise< T >::ptr &p)
completion_handler_impl(const Functor &f)
virtual ~completion_handler()
#define FC_CANCELATION_REASON_DEFAULT_ARG
virtual void cancel(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG)
future & operator=(future< T > &&f)
static ptr create(const char *desc FC_TASK_NAME_DEFAULT_ARG)
static microseconds maximum()
std::shared_ptr< exception > exception_ptr
promise(const char *desc)
static ptr create(const char *desc FC_TASK_NAME_DEFAULT_ARG)
void on_complete(CompletionHandler &&c)
static ptr create(bool fulfilled, const char *desc FC_TASK_NAME_DEFAULT_ARG)
void wait(const microseconds &timeout=microseconds::maximum())
void wait(const microseconds &timeout=microseconds::maximum())
void wait_until(const time_point &tp)
void on_complete(CompletionHandler &&c)
static ptr create(const T &val)
future(const future< void > &f)
future & operator=(future< void > &&f)
future(const typename promise< void >::ptr &p)
#define FC_TASK_NAME_DEFAULT_ARG
promise(bool fulfilled, const char *desc)
void _on_complete(detail::completion_handler *c)
const char * get_desc() const
void _set_value(const void *v)
const T & wait_until(const time_point &tp)
void cancel_and_wait(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG)
void _wait_until(const time_point &timeout_us)
void set_value(const T &v)
const T & wait_until(const time_point &tp) const
const T & wait(const microseconds &timeout=microseconds::maximum()) const
Defines exception's used by fc.
std::shared_ptr< promise_base > ptr
void set_exception(const fc::exception_ptr &e)
future(typename promise< void >::ptr &&p)
void cancel(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG) const
static ptr create(T &&val)
future(const future< T > &f)
provides stack-based nullable value similar to boost::optional
std::shared_ptr< promise< void > > ptr
virtual void on_complete(const void *v, const fc::exception_ptr &e)=0
void on_complete(CompletionHandler &&c)
void cancel_and_wait(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG)
future(typename promise< T >::ptr &&p)
promise(const char *desc)
void _wait(const microseconds &timeout_us)