Condy v1.8
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
coro.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
9#include <coroutine>
10#include <utility>
11
12namespace condy {
13
24template <typename T = void, typename Allocator = void>
25class [[nodiscard]] Coro {
26public:
27 using promise_type = detail::Promise<T, Allocator>;
28
29 Coro(std::coroutine_handle<promise_type> h) : handle_(h) {}
30 Coro(Coro &&other) noexcept : handle_(other.release()) {}
31
32 Coro(const Coro &) = delete;
33 Coro &operator=(const Coro &) = delete;
34 Coro &operator=(Coro &&other) = delete;
35
36 ~Coro() {
37 if (handle_) {
38 handle_.destroy();
39 }
40 }
41
42public:
50 auto operator co_await() noexcept {
51 return detail::CoroAwaiter<T, Allocator>{release()};
52 }
53
54 std::coroutine_handle<promise_type> release() noexcept {
55 return std::exchange(handle_, nullptr);
56 }
57
58private:
59 std::coroutine_handle<promise_type> handle_;
60};
61
62} // namespace condy
Coroutine implementation details.
The main namespace for the Condy library.
Definition condy.hpp:37