template <typename E, typename F, typename...Ts>
auto when_all(E e, F f, future<Ts>... args)
(1)
template <typename E, typename F, typename I>
auto when_all(E e, F f, const std::pair<I,I>& range)
(2)
  1. This function create a joining future. When all passed args futures are fullfilled, then the continuation tasks defined with f is scheduled on the executor e.

  2. This function create a joining future

Parameters

e

Executor which is used to schedule the resulting task

f

Callable object that implements the task

args

Futures that shall be joined

range

a range of futures of type U, specified by a half open range. All futures must succeed, before the continuation is triggered. It takes a vector<U> filled with all results as result.

Return value

a future that joins all passed arguments and passes them to the associated function object

Example 1

#include <iostream>
#include <string>
#include <thread>
#include <stlab/concurrency/default_executor.hpp>
#include <stlab/concurrency/future.hpp>

using namespace std;
using namespace stlab;

int main() {
    auto argument1 = async(default_executor, [] { return 42; });
    auto argument2 = async(default_executor, [] { return string("The answer is"); });

    auto result = when_all(default_executor, [](int answer, std::string text) {
        cout << text << " " << answer << '\n';
    }, argument1, argument2);

    // Waiting just for illustrational purpose
    while (!result.get_try()) { this_thread::sleep_for(chrono::milliseconds(1)); }
}

/*
    Result:

        The answer is 42
*/