| 3 | using namespace std::chrono_literals; |
| 4 | |
| 5 | task<> g(stop_token token) { |
| 6 | printf("g() is running...\n"); |
| 7 | |
| 8 | stop_callback guard{token, [] { |
| 9 | printf("Callback is triggerd\n"); |
| 10 | }}; |
| 11 | |
| 12 | co_await timeout(1s); |
| 13 | |
| 14 | // It is your responsibility to check |
| 15 | // whether the task has been cancelled. |
| 16 | if (token.stop_requested()) { |
| 17 | printf("g() exits early\n"); |
| 18 | co_return; |
| 19 | } |
| 20 | |
| 21 | printf("g() finished\n"); |
| 22 | } |
| 23 | |
| 24 | task<> f() { |
| 25 | // The same as std::stop_source. |
no test coverage detected