BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
signals.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #if defined(_MSC_VER) && _MSC_VER >= 1400
4 #pragma warning(push)
5 #pragma warning(disable:4996)
6 #endif
7 
8 #include <boost/signals2/signal.hpp>
9 
10 #if defined(_MSC_VER) && _MSC_VER >= 1400
11 #pragma warning(pop)
12 #endif
13 
14 #include <fc/thread/future.hpp>
15 #include <fc/thread/thread.hpp>
16 
17 namespace fc {
18 #if !defined(BOOST_NO_TEMPLATE_ALIASES)
19  template<typename T>
20  using signal = boost::signals2::signal<T>;
21 
23 #else
24 
30  template <class T>
31  class signal : public boost::signals2::signal<T>
32  {
33  public:
34  };
35 #endif
36 
37  template<typename T>
38  inline T wait( boost::signals2::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
39  typename promise<T>::ptr p = promise<T>::create("fc::signal::wait");
40  boost::signals2::scoped_connection c( sig.connect( [=]( T t ) { p->set_value(t); } ));
41  return p->wait( timeout_us );
42  }
43 
44  inline void wait( boost::signals2::signal<void()>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
45  promise<void>::ptr p = promise<void>::create("fc::signal::wait");
46  boost::signals2::scoped_connection c( sig.connect( [=]() { p->set_value(); } ));
47  p->wait( timeout_us );
48  }
49 }
fc::promise::ptr
std::shared_ptr< promise< T > > ptr
Definition: future.hpp:111
fc::promise::wait
const T & wait(const microseconds &timeout=microseconds::maximum())
Definition: future.hpp:127
fc
Definition: api.hpp:15
fc::signal
boost::signals2::signal< T > signal
Definition: signals.hpp:20
fc::promise::create
static ptr create(const char *desc FC_TASK_NAME_DEFAULT_ARG)
Definition: future.hpp:114
fc::microseconds::maximum
static microseconds maximum()
Definition: time.hpp:15
fc::wait
T wait(boost::signals2::signal< void(T)> &sig, const microseconds &timeout_us=microseconds::maximum())
Definition: signals.hpp:38
thread.hpp
fc::microseconds
Definition: time.hpp:12
future.hpp
fc::scoped_connection
boost::signals2::scoped_connection scoped_connection
Definition: signals.hpp:22