Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
sync_wait.h File Reference

Utility functions for quickly converting a awaitable to a std::future. More...

#include <asyncpp/fire_and_forget.h>
#include <future>
Include dependency graph for sync_wait.h:

Go to the source code of this file.

Functions

template<typename T , typename Awaitable >
requires (!std::is_void_v<T>)
std::future< T > asyncpp::as_promise (Awaitable &&awaiter)
 Execute the given awaitable and return a std::promise representing the call.
 
template<typename T , typename Awaitable >
requires (std::is_void_v<T>)
std::future< void > asyncpp::as_promise (Awaitable &&awaiter)
 Execute the given awaitable and return a std::promise representing the call.
 
auto asyncpp::as_promise (auto &&awaiter)
 Execute the given awaitable and return a std::promise representing the call.
 

Detailed Description

Utility functions for quickly converting a awaitable to a std::future.

Function Documentation

◆ as_promise() [1/3]

auto asyncpp::as_promise ( auto && awaiter)

Execute the given awaitable and return a std::promise representing the call.

Note
The returned promise will block until the async function finishes or throws.
This function tries to autodetect the return type of the co_await expression. However the C++20 coroutines have lots of extension points which makes this hard (impossible?) to do in all cases. If the detection fails you can use the above functions and explicitly specify the return type.

This can be used to synchronously wait for the result of a coroutine.

◆ as_promise() [2/3]

template<typename T , typename Awaitable >
requires (!std::is_void_v<T>)
std::future< T > asyncpp::as_promise ( Awaitable && awaiter)

Execute the given awaitable and return a std::promise representing the call.

Note
The returned promise will block until the async function finishes or throws.

This can be used to synchronously wait for the result of a coroutine.

◆ as_promise() [3/3]

template<typename T , typename Awaitable >
requires (std::is_void_v<T>)
std::future< void > asyncpp::as_promise ( Awaitable && awaiter)

Execute the given awaitable and return a std::promise representing the call.

Note
The returned promise will block until the async function finishes or throws.

This can be used to synchronously wait for the result of a coroutine.