run and run_forever
run
and run_forever
are top-level functions used for running coroutines. run
runs a coroutine until it completes, while run_forever
runs coroutines indefinitely
via the IO service.
Prototype
template<typename IoService>
void run_forever(IoService ios); // (1)
template<typename Sender>
Sender::value_type run(Sender s); // (2)
template<typename Sender, typename IoService>
Sender::value_type run(Sender s, IoService ios); // (3)
- Run the IO service indefinitely
- Start the sender and wait until it completes. The sender must complete inline as there's no way to wait for it to complete.
- Same as (2) but the sender can complete not-inline.
Requirements
IoService
is an IO service, and Sender
is a sender.
Arguments
IoService
- the IO service to use to wait for completion.Sender
- the sender to start.
Return value
- This function does not return.
- This function returns the result value obtained from the sender.
- Same as (2).
Examples
int i = async::run([] () -> async::result<int> {
co_return 1;
}());
std::cout << i << std::endl;
Output:
1