Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions async_simple/coro/FutureAwaiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ struct FutureAwaiter {
future_ = makeReadyFuture<T>(
std::make_exception_ptr(async_simple::SignalException(
SignalType::Terminate,
"FutureAwaiter is only allowed to be called by Lazy")));
"FutureAwaiter is cancelled by signal")));
// Add thread fence, make sure future_ has being assigned before
// continuation or cancellation in arm.
std::atomic_thread_fence(std::memory_order_acq_rel);
auto state = std::make_shared<std::atomic<bool>>(true);

if (!signalHelper{Terminate}.tryEmplace(
cancellationSlot,
[continuation, ex, ctx, state](auto&&...) mutable {
Expand Down Expand Up @@ -116,8 +118,9 @@ auto operator co_await(Future<T>&& future) {
}

template <typename T>
[[deprecated("Require an rvalue future.")]]
auto operator co_await(T&& future) requires IsFuture<std::decay_t<T>>::value {
[[deprecated("Require an rvalue future.")]] auto operator co_await(T&& future)
requires IsFuture<std::decay_t<T>>::value
{
return std::move(operator co_await(std::move(future)));
}

Expand Down
6 changes: 2 additions & 4 deletions async_simple/coro/test/FutureAwaiterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ TEST_F(FutureAwaiterTest, testWithFuture) {
syncAwait(lazy3().via(&ex2));
}

// The test fails in debug mode with internal CI. Disable it to keep the CI green.
#if 0
TEST_F(FutureAwaiterTest, testWithFutureCancel) {
async_simple::executors::SimpleExecutor ex1(2);
auto lazy = [&]() -> Lazy<> {
Expand Down Expand Up @@ -109,15 +107,15 @@ TEST_F(FutureAwaiterTest, testWithFutureCancel) {
int ret = 0;
try {
ret = co_await std::move(fut);
} catch (...) {
} catch (const std::exception& e) {
std::cout << e.what() << std::endl;
}
EXPECT_EQ(ret, 2);
};
syncAwait(collectAll<async_simple::Terminate>(
lazy2().via(&ex1),
async_simple::coro::sleep(std::chrono::seconds::max()).via(&ex1)));
}
#endif

namespace detail {

Expand Down
Loading