Condy v1.1.0
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
8#include <coroutine>
9#include <utility>
10
11namespace condy {
12
13template <typename T, typename Allocator> class Promise;
14
25template <typename T = void, typename Allocator = void>
26class [[nodiscard]] Coro {
27public:
28 using promise_type = Promise<T, Allocator>;
29
30 Coro(std::coroutine_handle<promise_type> h) : handle_(h) {}
31 Coro(Coro &&other) noexcept : handle_(other.release()) {}
32
33 Coro(const Coro &) = delete;
34 Coro &operator=(const Coro &) = delete;
35 Coro &operator=(Coro &&other) = delete;
36
37 ~Coro() {
38 if (handle_) {
39 handle_.destroy();
40 }
41 }
42
43public:
51 auto operator co_await() noexcept;
52
53 std::coroutine_handle<promise_type> release() noexcept {
54 return std::exchange(handle_, nullptr);
55 }
56
57private:
58 std::coroutine_handle<promise_type> handle_;
59};
60
61} // namespace condy
62
63#include "condy/coro.inl"
Coroutine implementation details.
The main namespace for the Condy library.
Definition condy.hpp:28