mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
cancellation.hpp
1#ifndef MRS_LIB_CORO_CANCELLATION_HPP_
2#define MRS_LIB_CORO_CANCELLATION_HPP_
3
4
5#include <cassert>
6#include <coroutine>
7#include <stop_token>
8
9#include "mrs_lib/coro/internal/continuation.hpp"
10#include "mrs_lib/coro/internal/immediate_awaitable.hpp"
11
12
13namespace mrs_lib::coro
14{
15
16 namespace internal
17 {
18
19 class [[nodiscard]] GetTaskStopTokenAwaiter
20 {
21 public:
22 bool await_ready();
23
24 template <typename T>
25 bool await_suspend(std::coroutine_handle<T> handle)
26 {
27 return await_suspend(CancellableContinuation(handle));
28 }
29 bool await_suspend(CancellableContinuation continuation);
30
31 std::stop_token await_resume();
32
33 private:
34 std::stop_token token_;
35 };
36
37 } // namespace internal
38
45
46} // namespace mrs_lib::coro
47
48#endif // MRS_LIB_CORO_CANCELLATION_HPP_
Owning coroutine handle supporting cancellation.
Definition continuation.hpp:54
Helper class to force awaiting a result in the current expression.
Definition immediate_awaitable.hpp:16