|
1 | 1 | #pragma once |
2 | 2 |
|
| 3 | +#include <cassert> |
3 | 4 | #include <coroutine> |
4 | 5 | #include <functional> |
5 | 6 | #include <memory> |
@@ -146,7 +147,7 @@ struct final_awaitable { |
146 | 147 | if (h.promise().parent_handle_) { |
147 | 148 | return h.promise().parent_handle_; |
148 | 149 | } else { |
149 | | - if (h.done() && !h.promise().awaitable_) { |
| 150 | + if (!h.promise().awaitable_) { |
150 | 151 | h.destroy(); |
151 | 152 | } |
152 | 153 | return std::noop_coroutine(); |
@@ -207,13 +208,19 @@ struct awaitable { |
207 | 208 | /// enable move |
208 | 209 | awaitable(awaitable&& other) noexcept : current_coro_handle_(other.current_coro_handle_) { |
209 | 210 | CORO_DEBUG_LIFECYCLE("awaitable: move(c): %p to %p, h: %p", &other, this, current_coro_handle_.address()); |
| 211 | + if (current_coro_handle_) { |
| 212 | + current_coro_handle_.promise().awaitable_ = this; |
| 213 | + } |
210 | 214 | other.current_coro_handle_ = nullptr; |
211 | 215 | } |
212 | 216 | awaitable& operator=(awaitable&& other) noexcept { |
213 | 217 | CORO_DEBUG_LIFECYCLE("awaitable: move(=): %p to %p, h: %p", &other, this, current_coro_handle_.address()); |
214 | 218 | if (this != &other) { |
215 | 219 | if (current_coro_handle_) current_coro_handle_.destroy(); |
216 | 220 | current_coro_handle_ = other.current_coro_handle_; |
| 221 | + if (current_coro_handle_) { |
| 222 | + current_coro_handle_.promise().awaitable_ = this; |
| 223 | + } |
217 | 224 | other.current_coro_handle_ = nullptr; |
218 | 225 | } |
219 | 226 | return *this; |
@@ -339,6 +346,7 @@ struct callback_awaiter : detail::callback_awaiter_base<T> { |
339 | 346 | template <typename Promise> |
340 | 347 | void await_suspend(std::coroutine_handle<Promise> handle) { |
341 | 348 | auto executor = handle.promise().executor_; |
| 349 | + assert(executor && "executor must be set before using callback_awaiter"); |
342 | 350 | switch (callback_function_.index()) { |
343 | 351 | case 0: { |
344 | 352 | auto& func = std::get<0>(callback_function_); |
@@ -402,7 +410,7 @@ struct current_executor_awaiter { |
402 | 410 |
|
403 | 411 | } // namespace detail |
404 | 412 |
|
405 | | -[[nodiscard]] detail::current_executor_awaiter current_executor() { |
| 413 | +[[nodiscard]] inline detail::current_executor_awaiter current_executor() { |
406 | 414 | return detail::current_executor_awaiter{}; |
407 | 415 | } |
408 | 416 |
|
|
0 commit comments