16 #include <type_traits>
40 typename std::enable_if<!std::is_void<
typename result_of<F()>::
type>::value>::
type* =
nullptr);
44 Future<Nothing>
async(
46 typename std::enable_if<std::is_void<
typename result_of<F()>::
type>::value>::
type* =
nullptr);
49 #define TEMPLATE(Z, N, DATA) \
50 template <typename F, ENUM_PARAMS(N, typename A)> \
51 Future<typename result_of<F(ENUM_PARAMS(N, A))>::type> async( \
53 ENUM_BINARY_PARAMS(N, A, a), \
54 typename std::enable_if<!std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type* = nullptr); \
57 template <typename F, ENUM_PARAMS(N, typename A)> \
58 Future<Nothing> async( \
60 ENUM_BINARY_PARAMS(N, A, a), \
61 typename std::enable_if<std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type* = nullptr); // NOLINT(whitespace/line_length)
68 class AsyncExecutorProcess :
public Process<AsyncExecutorProcess>
74 virtual ~AsyncExecutorProcess() {}
77 AsyncExecutorProcess(
const AsyncExecutorProcess&);
78 AsyncExecutorProcess& operator=(
const AsyncExecutorProcess&);
82 typename std::enable_if<
92 typename std::enable_if<
101 #define TEMPLATE(Z, N, DATA) \
104 ENUM_PARAMS(N, typename A), \
105 typename std::enable_if< \
107 typename result_of<F(ENUM_PARAMS(N, A))>::type>::value, \
109 typename result_of<F(ENUM_PARAMS(N, A))>::type execute( \
110 const F& f, ENUM_BINARY_PARAMS(N, A, a)) \
113 return f(ENUM_PARAMS(N, a)); \
118 ENUM_PARAMS(N, typename A), \
119 typename std::enable_if< \
121 typename result_of<F(ENUM_PARAMS(N, A))>::type>::value, \
124 const F& f, ENUM_BINARY_PARAMS(N, A, a)) \
127 f(ENUM_PARAMS(N, a)); \
141 template <
typename F>
144 typename std::enable_if<!std::is_void<
typename result_of<F()>::
type>::value>::
type*);
146 template <
typename F>
149 typename std::enable_if<std::is_void<
typename result_of<F()>::
type>::value>::
type*);
151 #define TEMPLATE(Z, N, DATA) \
152 template <typename F, ENUM_PARAMS(N, typename A)> \
153 friend Future<typename result_of<F(ENUM_PARAMS(N, A))>::type> async( \
155 ENUM_BINARY_PARAMS(N, A, a), \
156 typename std::enable_if<!std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type*); \
158 template <typename F, ENUM_PARAMS(N, typename A)> \
159 friend Future<Nothing> async( \
161 ENUM_BINARY_PARAMS(N, A, a), \
162 typename std::enable_if<std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type*); // NOLINT(whitespace/line_length)
178 template <
typename F>
181 typename std::enable_if<!std::is_void<
typename result_of<F()>::
type>::value>::
type* =
nullptr)
185 &AsyncExecutorProcess::execute<F>;
190 template <
typename F>
193 typename std::enable_if<std::is_void<
typename result_of<F()>::
type>::value>::
type* =
nullptr)
196 Nothing(AsyncExecutorProcess::*method)(
const F&) =
197 &AsyncExecutorProcess::execute<F>;
202 #define TEMPLATE(Z, N, DATA) \
203 template <typename F, ENUM_PARAMS(N, typename A)> \
204 Future<typename result_of<F(ENUM_PARAMS(N, A))>::type> execute( \
206 ENUM_BINARY_PARAMS(N, A, a), \
207 typename std::enable_if<!std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type* = nullptr) \
210 typename result_of<F(ENUM_PARAMS(N, A))>::type(AsyncExecutorProcess::*method)(const F&, ENUM_PARAMS(N, A)) = \
211 &AsyncExecutorProcess::execute<F, ENUM_PARAMS(N, A)>; \
213 return dispatch(process, method, f, ENUM_PARAMS(N, a)); \
216 template <typename F, ENUM_PARAMS(N, typename A)> \
217 Future<Nothing> execute( \
219 ENUM_BINARY_PARAMS(N, A, a), \
220 typename std::enable_if<std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type* = nullptr) \
223 Nothing(AsyncExecutorProcess::*method)(const F&, ENUM_PARAMS(N, A)) = \
224 &AsyncExecutorProcess::execute<F, ENUM_PARAMS(N, A)>; \
226 return dispatch(process, method, f, ENUM_PARAMS(N, a)); \
237 template <
typename F>
240 typename std::enable_if<!std::is_void<
typename result_of<F()>::
type>::value>::
type*)
246 template <
typename F>
249 typename std::enable_if<std::is_void<
typename result_of<F()>::
type>::value>::
type*)
255 #define TEMPLATE(Z, N, DATA) \
256 template <typename F, ENUM_PARAMS(N, typename A)> \
257 Future<typename result_of<F(ENUM_PARAMS(N, A))>::type> async( \
259 ENUM_BINARY_PARAMS(N, A, a), \
260 typename std::enable_if<!std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type*) \
262 return AsyncExecutor().execute(f, ENUM_PARAMS(N, a)); \
265 template <typename F, ENUM_PARAMS(N, typename A)> \
266 Future<Nothing> async( \
268 ENUM_BINARY_PARAMS(N, A, a), \
269 typename std::enable_if<std::is_void<typename result_of<F(ENUM_PARAMS(N, A))>::type>::value>::type*) \
271 return AsyncExecutor().execute(f, ENUM_PARAMS(N, a)); \
279 #endif // __ASYNC_HPP__
std::string generate(const std::string &prefix="")
Returns 'prefix(N)' where N represents the number of instances where the same prefix (wrt...
Definition: nothing.hpp:16
void execute(const std::string &script)
F && f
Definition: defer.hpp:270
REPEAT_FROM_TO(1, 13, TEMPLATE, _) class AsyncExecutorProcess
Definition: async.hpp:63
Definition: process.hpp:72
UPID spawn(ProcessBase *process, bool manage=false)
Spawn a new process.
void terminate(const UPID &pid, bool inject=true)
Sends a TerminateEvent to the given process.
Definition: async.hpp:137
friend Future< typename result_of< F()>::type > async(const F &f, typename std::enable_if<!std::is_void< typename result_of< F()>::type >::value >::type *)
void dispatch(const PID< T > &pid, void(T::*method)())
Definition: dispatch.hpp:174
Future< typename result_of< F()>::type > async(const F &f, typename std::enable_if<!std::is_void< typename result_of< F()>::type >::value >::type *=nullptr)
Definition: async.hpp:238
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:279
#define TEMPLATE(Z, N, DATA)
Definition: async.hpp:255
Try< uint32_t > type(const std::string &path)
Definition: process.hpp:493
Definition: future.hpp:57