13 #ifndef __PROCESS_COLLECT_HPP__ 14 #define __PROCESS_COLLECT_HPP__ 39 Future<std::vector<T>>
collect(
const std::vector<Future<T>>& futures);
44 template <
typename... Ts>
45 Future<std::tuple<Ts...>>
collect(
const Future<Ts>&... futures);
51 Future<std::vector<Future<T>>>
await(
const std::vector<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::vector<T>>* _promise)
141 foreach (
const Future<T>& future, futures) {
142 future.
onAny(
defer(
this, &CollectProcess::waited, lambda::_1));
173 promise->
fail(
"Collect failed: " + future.
failure());
176 promise->
fail(
"Collect failed: future discarded");
181 if (ready == futures.size()) {
182 std::vector<T> values;
183 values.reserve(futures.size());
185 foreach (
const Future<T>& future, futures) {
186 values.push_back(future.
get());
189 promise->
set(std::move(values));
195 const std::vector<Future<T>> futures;
201 template <
typename T>
221 promise->future().onDiscard(
defer(
this, &AwaitProcess::discarded));
223 foreach (
const Future<T>& future, futures) {
224 future.
onAny(
defer(
this, &AwaitProcess::waited, lambda::_1));
257 if (ready == futures.size()) {
259 promise->set(std::move(futures));
264 std::vector<Future<T>> futures;
273 template <
typename T>
277 if (futures.empty()) {
278 return std::vector<T>();
288 template <
typename... Ts>
291 std::vector<Future<Nothing>> wrappers = {
300 return std::make_tuple(futures.
get()...);
308 template <
typename T>
312 if (futures.empty()) {
324 template <
typename... Ts>
327 std::vector<Future<Nothing>> wrappers = {
336 return std::make_tuple(futures...);
339 return await(wrappers)
345 #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
~AwaitProcess() override
Definition: collect.hpp:213
F && f
Definition: defer.hpp:270
const T & get() const
Definition: future.hpp:1294
bool set(const T &_t)
Definition: future.hpp:827
bool fail(const std::string &message)
Definition: future.hpp:903
const Future< T > & onDiscard(DiscardCallback &&callback) const
Definition: future.hpp:1354
AwaitProcess(const std::vector< Future< T >> &_futures, Promise< std::vector< Future< T >>> *_promise)
Definition: collect.hpp:205
Future< std::vector< Future< T > > > await(const std::vector< Future< T >> &futures)
Definition: collect.hpp:309
bool await(const process::Future< T > &future, const Duration &duration)
Definition: gtest.hpp:67
Definition: process.hpp:72
bool discard()
Definition: future.hpp:1157
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.
bool isPending() const
Definition: future.hpp:1208
Future< std::vector< T > > collect(const std::vector< Future< T >> &futures)
Definition: collect.hpp:274
bool isDiscarded() const
Definition: future.hpp:1222
void initialize() override
Invoked when a process gets spawned.
Definition: collect.hpp:136
const Future< T > & onAny(AnyCallback &&callback) const
Definition: future.hpp:1442
CollectProcess(const std::vector< Future< T >> &_futures, Promise< std::vector< T >> *_promise)
Definition: collect.hpp:122
~CollectProcess() override
Definition: collect.hpp:130
Definition: collect.hpp:202
Definition: future.hpp:74
const Future< T > & onAbandoned(AbandonedCallback &&callback) const
Definition: future.hpp:1332
#define CHECK_READY(expression)
Definition: check.hpp:29
Future< X > then(lambda::CallableOnce< Future< X >(const T &)> f) const
Definition: future.hpp:1576
Definition: attributes.hpp:24
Definition: executor.hpp:48
void then(lambda::CallableOnce< X(const T &)> &&f, std::unique_ptr< Promise< X >> promise, const Future< T > &future)
Definition: future.hpp:1487
Future< T > future() const
Definition: future.hpp:913
void initialize() override
Invoked when a process gets spawned.
Definition: collect.hpp:218
bool discard()
Definition: future.hpp:810
void discarded(Future< U > future)
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
const std::string & failure() const
Definition: future.hpp:1320
Definition: process.hpp:505
Deferred< void()> defer(const PID< T > &pid, void(T::*method)())
Definition: defer.hpp:35
bool isFailed() const
Definition: future.hpp:1229
Definition: future.hpp:58