-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AbortRegistration::handle #2712
Conversation
Thanks for the PR. This looks good to me. I thought |
The Edit: I mean by "new_handle" it kind of suggests the creation of a entirely unrelated "new" abortable, especially when there is "AbortHandle::new_pair" around |
@taiki-e I've changed the name to Compare let handle = abort_reg.create_handle() to let handle = abort_reg.new_handle() to let handle = abort_reg.handle() The last one express the fixed dependency of handle on the registration, and its shared reference nature. |
Co-authored-by: ZhennanWu <znjameswu@gmail.com>
Co-authored-by: ZhennanWu <znjameswu@gmail.com>
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [futures](https://rust-lang.github.io/futures-rs) ([source](https://github.com/rust-lang/futures-rs)) | dependencies | patch | `0.3.26` -> `0.3.27` | --- ### Release Notes <details> <summary>rust-lang/futures-rs</summary> ### [`v0.3.27`](https://github.com/rust-lang/futures-rs/blob/HEAD/CHANGELOG.md#​0327---2023-03-11) [Compare Source](rust-lang/futures-rs@0.3.26...0.3.27) - Add `TryFlattenUnordered` ([#​2577](rust-lang/futures-rs#2577), [#​2590](rust-lang/futures-rs#2590), [#​2606](rust-lang/futures-rs#2606), [#​2607](rust-lang/futures-rs#2607)) - Add `AbortHandle::is_aborted` ([#​2710](rust-lang/futures-rs#2710)) - Add `AbortRegistration::handle` ([#​2712](rust-lang/futures-rs#2712)) - Make `BiLock` strict-provenance compatible ([#​2716](rust-lang/futures-rs#2716)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS42LjAiLCJ1cGRhdGVkSW5WZXIiOiIzNS42LjAifQ==--> Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1816 Reviewed-by: crapStone <crapstone@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Allow to create
AbortHandle
fromAbortRegistration
. The implementation is obvious. SinceAbortHandle
is alreadyClone
, this API should not create too much problem.Motivation
The intended use case is pretty niche. I'll try to explain. There is this single scenario where we have access to
AbortRegistration
, but can't have access toAbortHandle
.I'm trying to create a zero-cost abstraction over the different async executors. One major concern is to ensure the uniformity of cancellation propagation between different async executor backends. When I try to implement a cancel-on-drop semantic, due to limitations of
async-std
, it requires anAbortable
wrapper to ensure the cancellation propagation. (as others have also found out).Users may well combine a cancel-on-drop spawn with an
Abortable
, which results in two consecutiveAbortable
wrappers inasync-std
, which may be flattened into one. For zero-cost abstraction, a more specific "cancel-on-drop-with-Abortable" semantic is needed to avoid the extra cost onasync-std
. Which, unfortunately, has no other signature than the following.We cannot add an
AbortHandle
parameter since other executors do not needAbortHandle
to propagate the cancellation. Adding one violates zero-cost abstraction. However, onasync-std
we do need anAbortHandle
for cancellation propagation. This prompts the need for this API.