Condy v1.5.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
sync_wait.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "condy/coro.hpp"
9#include "condy/runtime.hpp"
10#include "condy/task.hpp"
11
12namespace condy {
13
23template <typename T, typename Allocator>
25 auto t = co_spawn(runtime, std::move(coro));
26 runtime.allow_exit();
27 runtime.run();
28 return t.wait();
29}
30
37 static RuntimeOptions options;
38 return options;
39}
40
50template <typename T, typename Allocator> T sync_wait(Coro<T, Allocator> coro) {
52 return sync_wait(runtime, std::move(coro));
53}
54
55} // namespace condy
Coroutine type used to define a coroutine function.
Definition coro.hpp:26
The event loop runtime for executing asynchronous.
Definition runtime.hpp:68
void allow_exit() noexcept
Allow the runtime to exit when there are no pending works.
Definition runtime.hpp:176
void run() noexcept
Run the runtime event loop in the current thread.
Definition runtime.hpp:220
Coroutine definitions.
The main namespace for the Condy library.
Definition condy.hpp:28
RuntimeOptions & default_runtime_options()
Get the default runtime options. This options will be used when using sync_wait without specifying ru...
Definition sync_wait.hpp:36
T sync_wait(Runtime &runtime, Coro< T, Allocator > coro)
Synchronously wait for a coroutine to complete in the given runtime.
Definition sync_wait.hpp:24
Task< T, Allocator > co_spawn(Runtime &runtime, Coro< T, Allocator > coro)
Spawn a coroutine as a task in the given runtime.
Definition task.hpp:266
Runtime type for running the io_uring event loop.
Interfaces for coroutine task management.