Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Classes | Public Member Functions | List of all members
seastar::coroutine::all< Futures > Class Template Reference

Detailed Description

template<typename... Futures>
requires (sizeof ...(Futures) > 0)
class seastar::coroutine::all< Futures >

Wait for serveral futures to complete in a coroutine.

all can be used to launch several computations concurrently and wait for all of them to complete. Computations are provided as callable objects (typically lambda coroutines) that are invoked by all. Waiting is performend by co_await and returns a tuple of values, one for each non-void future.

If one or more of the function objects throws an exception, or if one or more of the futures resolves to an exception, then the exception is thrown. All of the futures are waited for, even in the case of exceptions. If more than one exception is present, an arbitrary one is thrown.

Example

future<int> add() {
auto [a, b] = co_await all(
[] () -> future<int> {
co_await sleep(1ms);
co_return 2;
},
[] () -> future<int> {
co_await sleep(1ms);
co_return 3;
}
);
co_return a + b;
};
Definition: all.hh:117
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
future sleep(std::chrono::duration< Rep, Period > dur)
Definition: sleep.hh:48

Safe for use with lambda coroutines.

#include <seastar/coroutine/all.hh>

Public Member Functions

template<typename... Func>
requires (... && std::invocable<Func>) && (... && future_type<std::invoke_result_t<Func>>)
 all (Func &&... funcs)
 
awaiter operator co_await ()
 

The documentation for this class was generated from the following file: