- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
async.hpp
Go to the documentation of this file.
1 #pragma once
2
7 #ifndef _QI_ASYNC_HPP_
8 #define _QI_ASYNC_HPP_
9
10 #include <qi/eventloop.hpp>
11 #include <qi/future.hpp>
12 #include <qi/strand.hpp>
13
14 namespace qi
15 {
16 // some required forward declaration
17 namespace detail
18 {
19 template <typename F>
20 inline auto asyncMaybeActor(F&& cb, qi::Duration delay) ->
21 typename std::enable_if<detail::IsAsyncBind<F>::value, typename std::decay<decltype(cb())>::type>::type;
22
23 template <typename F>
24 inline auto asyncMaybeActor(F&& cb, qi::Duration delay) ->
25 typename std::enable_if<!detail::IsAsyncBind<F>::value,
26 qi::Future<typename std::decay<decltype(cb())>::type>>::type;
27
28 template <typename F>
29 inline auto asyncMaybeActor(F&& cb, qi::SteadyClockTimePoint timepoint) ->
30 typename std::enable_if<detail::IsAsyncBind<F>::value, typename std::decay<decltype(cb())>::type>::type;
31
32 template <typename F>
33 inline auto asyncMaybeActor(F&& cb, qi::SteadyClockTimePoint timepoint) ->
34 typename std::enable_if<!detail::IsAsyncBind<F>::value,
35 qi::Future<typename std::decay<decltype(cb())>::type>>::type;
36 } // detail
37
38 template <typename F>
39 inline auto asyncAt(F&& callback, qi::SteadyClockTimePoint timepoint)
40 -> decltype(qi::getEventLoop()->asyncAt(std::forward<F>(callback), timepoint))
41 {
42 return qi::getEventLoop()->asyncAt(std::forward<F>(callback), timepoint);
43 }
44
45 template <typename F>
46 inline auto asyncDelay(F&& callback, qi::Duration delay)
47 -> decltype(detail::asyncMaybeActor(std::forward<F>(callback), delay))
48 {
49 return detail::asyncMaybeActor(std::forward<F>(callback), delay);
50 }
51
52 template <typename F>
53 inline auto async(F&& callback)
54 -> decltype(asyncDelay(std::forward<F>(callback), qi::Duration(0)))
55 {
56 return asyncDelay(std::forward<F>(callback), qi::Duration(0));
57 }
58
61 template<typename R>
62 QI_API_DEPRECATED_MSG(Use 'asyncDelay' instead)
63 inline Future<R> async(boost::function<R()> callback, uint64_t usDelay);
64
65 template<typename R>
66 QI_API_DEPRECATED_MSG(Use 'asyncDelay' instead)
67 inline Future<R> async(boost::function<R()> callback, qi::Duration delay);
68
69 template<typename R>
70 QI_API_DEPRECATED_MSG(Use 'asyncAt' instead)
71 inline Future<R> async(boost::function<R()> callback, qi::SteadyClockTimePoint timepoint);
72
73 template<typename R>
74 QI_API_DEPRECATED_MSG(Use 'async' without explicit return type template arguement instead)
75 inline Future<R> async(detail::Function<R()> callback);
76
77 #ifdef DOXYGEN
78 template<typename R, typename Func, typename ArgTrack>
80 QI_API_DEPRECATED qi::Future<R> async(const Func& f, const ArgTrack& toTrack, ...);
81 #else
82 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)\
83 template <typename R, typename AF, typename ARG0 comma ATYPEDECL>\
84 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::Duration delay = qi::Duration(0))\
85 \
86 template <typename R, typename AF, typename ARG0 comma ATYPEDECL>\
87 inline QI_API_DEPRECATED Future<R> async(const AF& fun, const ARG0& arg0 comma ADECL, qi::SteadyClockTimePoint timepoint)\
88 QI_GEN(genCall)
89 #undef genCall
90 #endif
91
96 template<typename T, typename Duration>
97 Future<T> cancelOnTimeout(Future<T> fut, Duration timeout);
98
99 } // qi
100
101 #include <qi/detail/async.hxx>
102 #endif // _QI_ASYNC_HPP
qi::asyncDelay
auto asyncDelay(F &&callback, qi::Duration delay) -> decltype(detail::asyncMaybeActor(std::forward< F >(callback), delay))
Definition: async.hpp:46
qi::Future
Definition: executioncontext.hpp:20
qi::SteadyClockTimePoint
SteadyClock::time_point SteadyClockTimePoint
Steady clock time point.
Definition: clock.hpp:211
qi::Duration
NanoSeconds Duration
Definition: clock.hpp:32
qi::detail::asyncMaybeActor
auto asyncMaybeActor(F &&cb, qi::Duration delay) -> typename std::enable_if< detail::IsAsyncBind< F >::value, typename std::decay< decltype(cb())>::type >::type
Definition: async.hxx:18
async.hxx
strand.hpp
QI_API_DEPRECATED_MSG
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:55
qi::async
auto async(F &&callback) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0)))
Definition: async.hpp:53
eventloop.hpp
future.hpp
qi::getEventLoop
EventLoop * getEventLoop()
Returns the global eventloop, created on demand on first call.
qi::asyncAt
auto asyncAt(F &&callback, qi::SteadyClockTimePoint timepoint) -> decltype(qi::getEventLoop() ->asyncAt(std::forward< F >(callback), timepoint))
Definition: async.hpp:39
qi::ExecutionContext::asyncAt
qi::Future< R > asyncAt(F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options=defaultExecutionOptions())
call a callback asynchronously to be executed on tp
QI_API_DEPRECATED
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:41
qi::uint64_t
uint64_t uint64_t
Definition: types.hpp:66
qi::cancelOnTimeout
Future< T > cancelOnTimeout(Future< T > fut, Duration timeout)
Definition: async.hxx:147