The asio::experimental::generator has a asio::cancellation_state that can be accessed by co_await asio::this_coro::cacellation_state, just like asio::awaitable. But the get_cancellation_slot() return the slot that state resides in, not the slot of state,which is diffrent from asio::awaitable's implementation.
When generator got a token that has a associated cancellation_signal, the cancellation_state will be corrupted by async operation which will emplace a cancellation_handler in slot.
The
asio::experimental::generator
has aasio::cancellation_state
that can be accessed byco_await asio::this_coro::cacellation_state
, just likeasio::awaitable
. But theget_cancellation_slot()
return theslot
thatstate
resides in, not theslot of state
,which is diffrent fromasio::awaitable
's implementation.https://github.com/chriskohlhoff/asio/blob/79f17e970b6f661c275ad6fe0d7ed448e5e72c27/asio/include/asio/experimental/impl/coro.hpp#L36-L40
https://github.com/chriskohlhoff/asio/blob/79f17e970b6f661c275ad6fe0d7ed448e5e72c27/asio/include/asio/experimental/impl/coro.hpp#L601-L604
https://github.com/chriskohlhoff/asio/blob/79f17e970b6f661c275ad6fe0d7ed448e5e72c27/asio/include/asio/impl/awaitable.hpp#L749-L752
When
generator
got atoken
that has a associatedcancellation_signal
, thecancellation_state
will be corrupted by async operation which will emplace acancellation_handler
in slot.Perhaps the implementatin should be