facebookexperimental / facebookexperimental/libunifex

How to distinguish between cancellation from stop_when and ouside?

Open
#560 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.7k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

eg. call rpc with timeout using stop_when, and retry:
```cpp
int retryCount = 5;

while (retryCount > 0) {
-- retryCount;
auto result = co_await
done_as_optional(stop_when(fakeRpc(), s.schedule_after(2s)));
if (result) {
std::cout << "Task done with " << *result << std::endl;
co_return *result;
} else {
std::cout << "Retry..." << std::endl;
}
}
```

But if this coroutine is canceled outside by stop_source, stop_when is canceled, and several retries run instantly.
How to tell if canceled by stop_when?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.