Uh oh!
There was an error while loading. Please reload this page.
feat: add cancellation_token method to RunningService - #218
Conversation
currently both RunningService::waiting and RunningService::cancel needs ownership of the RunningService instance, which makes it impossible to poll waiting() while other async task can cancel it A split() function is a common pattern to solve this
4t145
commented
May 25, 2025
Perhaps we can simply add a |
lucasfernog-crabnebula
commented
May 25, 2025
but DropGuard can't be cloned, unless you want to change how cancellation is handled (if you clone a cancellation token and keep a copy in the RunningService the drop will never be triggered - and currently it also needs an owned value) |
4t145
commented
May 26, 2025
I believe it still can be triggered, you can see the source code. https://docs.rs/tokio-util/0.7.15/src/tokio_util/sync/cancellation_token/guard.rs.html#22-26 |
lucasfernog-crabnebula
commented
May 26, 2025
@4t145 pushed |
I explicitly added the cancellation token as part of the service struct because i don't want to call .disarm() on the drop guard - i want to preserve the "cancel on drop" functionality alternatively we could also implement drop on our own |
4t145
commented
May 26, 2025
That's exactly what I meant |
Motivation and Context
currently both RunningService::waiting and RunningService::cancel needs ownership of the RunningService instance
this makes it impossible to poll waiting() while other async task can cancel it
A cancellation_token() function is solves this, cloning the tokio_util::sync::CancellationToken
so we can dispatch a cancel from a separate task
How Has This Been Tested?
Breaking Changes
No breaking change
Types of changes
Checklist
Additional context