Condy v1.1.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 try {
28 runtime.run();
29 } catch (...) {
30 t.detach(); // Just to avoid panic here
31 throw;
32 }
33 return t.wait();
34}
35
42 static RuntimeOptions options;
43 return options;
44}
45
55template <typename T, typename Allocator> T sync_wait(Coro<T, Allocator> coro) {
57 return sync_wait(runtime, std::move(coro));
58}
59
60} // namespace condy
Coroutine type used to define a coroutine function.
Definition coro.hpp:26
The event loop runtime for executing asynchronous.
Definition runtime.hpp:76
void run()
Run the runtime event loop in the current thread.
Definition runtime.hpp:229
void allow_exit()
Allow the runtime to exit when there are no pending works.
Definition runtime.hpp:173
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:41
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:240
Runtime type for running the io_uring event loop.
Runtime options.
Definition runtime_options.hpp:22
Interfaces for coroutine task management.