boost::capy::this_coro::stop_token

Tag object that yields the current stop token when awaited.

Synopsis

inline constexpr stop_token_tag stop_token = {};

Description

Use co_await this_coro::stop_token inside a coroutine whose promise type supports stop token access (e.g., inherits from context_awaitable_promise_base). The returned stop token reflects whatever token was passed to this coroutine when it was awaited.

Example

capy::task<void> cancellable_work()
{
    auto token = co_await capy::this_coro::stop_token;
    if (token.stop_requested())
        co_return;
}

Preconditions

An await_context must have been installed for this coroutine before the tag is awaited (see environment). Awaiting it without an installed environment is undefined behavior (an assertion fires in debug builds).

Behavior

  • Returns the installed environment's stop_token field. If the started chain installed an await_context whose stop_token was left default, the result is a default‐constructed std::stop_token (where stop_possible() returns false).

  • The returned token remains valid for the coroutine's lifetime.

  • This operation never suspends; await_ready() always returns true.