peerplays-fc/include/fc/signals.hpp

28 lines
819 B
C++
Raw Normal View History

2012-09-09 04:25:43 +00:00
#include <boost/signal.hpp>
#include <fc/future.hpp>
#include <fc/thread.hpp>
2012-09-11 03:13:31 +00:00
#include <fc/log.hpp>
2012-09-09 04:25:43 +00:00
namespace fc {
#if !defined(BOOST_NO_TEMPLATE_ALIASES)
2012-09-09 04:25:43 +00:00
template<typename T>
using signal = boost::signal<T>;
#else
#endif
2012-09-09 04:25:43 +00:00
template<typename T>
inline T wait( boost::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::max() ) {
typename promise<T>::ptr p(new promise<T>());
boost::signals::scoped_connection c = sig.connect( [=]( T t ) { p->set_value(t); } );
return p->wait( timeout_us );
}
inline void wait( boost::signal<void()>& sig, const microseconds& timeout_us=microseconds::max() ) {
promise<void>::ptr p(new promise<void>());
2012-09-11 03:33:09 +00:00
boost::signals::scoped_connection c = sig.connect( [=]() { p->set_value(); } );
2012-09-09 04:25:43 +00:00
p->wait( timeout_us );
}
}