1818
1919#ifndef ASYNC_SIMPLE_USE_MODULES
2020#include < atomic>
21+ #include < exception>
2122#include < memory>
2223#include < type_traits>
23- #include < variant>
2424#include " async_simple/Future.h"
2525#include " async_simple/Signal.h"
26+ #include " async_simple/Try.h"
2627#include " async_simple/coro/Lazy.h"
2728#include " async_simple/experimental/coroutine.h"
2829
@@ -41,6 +42,10 @@ struct FutureAwaiter {
4142 Executor* ex, Executor::Context ctx,
4243 Slot* cancellationSlot) {
4344 auto future = std::make_unique<Future<T>>(std::move (future_));
45+ future_ = makeReadyFuture<T>(
46+ std::make_exception_ptr (async_simple::SignalException (
47+ SignalType::Terminate,
48+ " FutureAwaiter is only allowed to be called by Lazy" )));
4449 auto state = std::make_shared<std::atomic<bool >>(true );
4550
4651 if (!signalHelper{Terminate}.tryEmplace (
@@ -59,12 +64,12 @@ struct FutureAwaiter {
5964 }
6065 auto future_ptr = future.get ();
6166 future_ptr->setContinuation (
62- [continuation, ex, ctx, state = std::move (state),
67+ [this , continuation, ex, ctx, state = std::move (state),
6368 future = std::move (future)](auto &&...) mutable {
6469 if (!state->exchange (false )) {
6570 return ;
6671 }
67- future = std::move (future);
72+ this -> future_ = std::move (* future);
6873 if (ex != nullptr ) {
6974 ex->checkin (continuation, ctx);
7075 } else {
@@ -101,10 +106,6 @@ struct FutureAwaiter {
101106 return true ;
102107 }
103108 auto await_resume () {
104- if (!future_.valid ()) {
105- throw async_simple::SignalException{
106- async_simple::Terminate, " async_simple::Future is canceled!" };
107- }
108109 if constexpr (!std::is_same_v<T, void >) {
109110 return std::move (future_.value ());
110111 }
0 commit comments