13 #ifndef __PROCESS_COLLECT_HPP__
14 #define __PROCESS_COLLECT_HPP__
44 template <
typename... Ts>
45 Future<std::tuple<Ts...>>
collect(
const Future<Ts>&... futures);
51 Future<std::list<Future<T>>>
await(
const std::list<Future<T>>& futures);
56 template <
typename... Ts>
57 Future<std::tuple<Future<Ts>...>>
await(
const Future<Ts>&... futures);
106 template <
typename T>
118 template <
typename T>
124 Promise<std::list<T>>* _promise)
141 foreach (
const Future<T>& future, futures) {
142 future.
onAny(
defer(
this, &CollectProcess::waited, lambda::_1));
170 void waited(
const Future<T>& future)
172 if (future.isFailed()) {
173 promise->
fail(
"Collect failed: " + future.failure());
175 }
else if (future.isDiscarded()) {
176 promise->
fail(
"Collect failed: future discarded");
181 if (ready == futures.size()) {
183 foreach (
const Future<T>& future, futures) {
184 values.push_back(future.get());
186 promise->
set(values);
192 const std::list<Future<T>> futures;
193 Promise<std::list<T>>* promise;
198 template <
typename T>
218 promise->future().onDiscard(
defer(
this, &AwaitProcess::discarded));
220 foreach (
const Future<T>& future, futures) {
221 future.
onAny(
defer(
this, &AwaitProcess::waited, lambda::_1));
249 void waited(
const Future<T>& future)
251 CHECK(!future.isPending());
254 if (ready == futures.size()) {
255 promise->set(futures);
260 const std::list<Future<T>> futures;
261 Promise<std::list<Future<T>>>* promise;
269 template <
typename T>
273 if (futures.empty()) {
274 return std::list<T>();
284 template <
typename... Ts>
287 std::list<Future<Nothing>> wrappers = {
296 return std::make_tuple(futures.
get()...);
304 template <
typename T>
308 if (futures.empty()) {
320 template <
typename... Ts>
323 std::list<Future<Nothing>> wrappers = {
332 return std::make_tuple(futures...);
335 return await(wrappers)
341 #endif // __PROCESS_COLLECT_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
Definition: collect.hpp:119
F && f
Definition: defer.hpp:270
const T & get() const
Definition: future.hpp:1310
bool set(const T &_t)
Definition: future.hpp:826
bool fail(const std::string &message)
Definition: future.hpp:902
virtual ~CollectProcess()
Definition: collect.hpp:130
const Future< T > & onDiscard(DiscardCallback &&callback) const
Definition: future.hpp:1370
Definition: process.hpp:72
bool discard()
Definition: future.hpp:1173
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.
virtual void initialize()
Invoked when a process gets spawned.
Definition: collect.hpp:136
const Future< T > & onAny(AnyCallback &&callback) const
Definition: future.hpp:1458
Definition: collect.hpp:199
Definition: future.hpp:73
const Future< T > & onAbandoned(AbandonedCallback &&callback) const
Definition: future.hpp:1348
Protocol< PromiseRequest, PromiseResponse > promise
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
#define CHECK_READY(expression)
Definition: check.hpp:29
Future< X > then(lambda::CallableOnce< Future< X >(const T &)> f) const
Definition: future.hpp:1592
Future< std::list< Future< T > > > await(const std::list< Future< T >> &futures)
Definition: collect.hpp:305
AwaitProcess(const std::list< Future< T >> &_futures, Promise< std::list< Future< T >>> *_promise)
Definition: collect.hpp:202
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
CollectProcess(const std::list< Future< T >> &_futures, Promise< std::list< T >> *_promise)
Definition: collect.hpp:122
void then(lambda::CallableOnce< X(const T &)> &&f, std::unique_ptr< Promise< X >> promise, const Future< T > &future)
Definition: future.hpp:1503
virtual ~AwaitProcess()
Definition: collect.hpp:210
Future< T > future() const
Definition: future.hpp:912
bool discard()
Definition: future.hpp:809
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
virtual void initialize()
Invoked when a process gets spawned.
Definition: collect.hpp:215
Definition: process.hpp:493
Deferred< void()> defer(const PID< T > &pid, void(T::*method)())
Definition: defer.hpp:35
Definition: future.hpp:57
Future< std::list< T > > collect(const std::list< Future< T >> &futures)
Definition: collect.hpp:270