7 #ifndef _QI_DETAIL_ASYNC_HXX_
8 #define _QI_DETAIL_ASYNC_HXX_
19 typename std::enable_if<detail::IsAsyncBind<F>::value,
typename std::decay<decltype(cb())>::type>::type
21 if (delay != qi::Duration::zero())
29 typename std::enable_if<!detail::IsAsyncBind<F>::value,
37 typename std::enable_if<detail::IsAsyncBind<F>::value,
typename std::decay<decltype(cb())>::type>::type
43 typename std::enable_if<!detail::IsAsyncBind<F>::value,
52 template <
typename F,
typename Arg0,
typename... Args>
54 typename std::enable_if<std::is_base_of<Actor, typename std::decay<Arg0>::type>::value,
60 template <
typename F,
typename Arg0,
typename... Args>
62 typename std::enable_if<!std::is_base_of<Actor, typename std::decay<Arg0>::type>::value,
63 typename std::decay<decltype((arg0->*cb)(std::forward<Args>(args)...))>::type>::type
65 QI_ASSERT(arg0 &&
"the pointer on which the member is called is null");
66 return (arg0->*cb)(std::forward<Args>(args)...);
98 template<
typename R,
typename Func,
typename ArgTrack>
102 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
103 template <typename R, typename AF, typename ARG0 comma ATYPEDECL> \
104 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::Duration delay = qi::Duration(0)) \
106 return detail::asyncMaybeActor(qi::bind(fun, arg0 comma AUSE), delay); \
108 template <typename R, typename AF, typename ARG0 comma ATYPEDECL> \
109 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::SteadyClockTimePoint timepoint) \
111 return detail::asyncMaybeActor(qi::bind(fun, arg0 comma AUSE), timepoint); \
131 catch (
const std::runtime_error& e)
133 qiLogVerbose(
"qi.Future") << errorMsg <<
"detail=" << e.what();
146 template<
typename T,
typename Duration>
151 detail::tryCancel(fut,
"cancelOnTimeout: timeout task failed to cancel the running task: ");
155 detail::tryCancel(cancelFut,
"cancelOnTimeout: running task failed to cancel the timeout task");
161 #endif // _QI_DETAIL_ASYNC_HXX_
auto asyncDelay(F &&callback, qi::Duration delay) -> decltype(detail::asyncMaybeActor(std::forward< F >(callback), delay))
DurationType< int64_t, boost::micro > MicroSeconds
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
#define qiLogVerbose(...)
Log in verbose mode. This level is not shown by default.
#define QI_ASSERT(expr__)
void tryCancel(Future< T > &fut, const char *errorMsg)
Future< R > async(const boost::function< R()> &callback, uint64_t usDelay)
Calls given function once after given delay in microseconds.
qi::Future< R > asyncDelay(F &&callback, qi::Duration delay, ExecutionOptions options=defaultExecutionOptions())
call a callback asynchronously to be executed in delay
auto then(FutureCallbackType type, F &&func) -> Future< typename std::result_of< F(Future< T >)>::type >
Execute a callback when the future is finished.
auto asyncMaybeActor(F &&cb, qi::Duration delay) -> typename std::enable_if< detail::IsAsyncBind< F >::value, typename std::decay< decltype(cb())>::type >::type
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
auto async(F &&callback) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0)))
EventLoop * getEventLoop()
Returns the global eventloop, created on demand on first call.
qi::Future< R > asyncAt(F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options=defaultExecutionOptions())
call a callback asynchronously to be executed on tp
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
auto invokeMaybeActor(F &&cb, Arg0 *arg0, Args &&...args) -> typename std::enable_if< std::is_base_of< Actor, typename std::decay< Arg0 >::type >::value, decltype(tryUnwrap(arg0->async(boost::bind(cb, arg0, std::forward< Args >(args)...)), 0))>::type
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
Future< T > cancelOnTimeout(Future< T > fut, Duration timeout)