Repository navigation
Conversation
…der and completion::Completer
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
disconnected(&self) -> impl Future<Output = ()>to senders and completers whose receiver disconnection is irreversible across two focused commits:disconnectedtompsc,mpmc, andspmcsenders: Exposedisconnectedonmpsc::{BoundedSender, UnboundedSender},mpmc::{BoundedSender, UnboundedSender}, andspmc::{BoundedSender, UnboundedSender}. Each future completes immediately once all receivers are dropped, stays ready on re-poll, isUnpin(andSendforT: Send), and unregisters only its own waker when cancelled.disconnectedtooneshot::Senderandcompletion::Completer: Exposedisconnectedononeshot::Sender(waking whenReceiveror a polledRecvfuture is dropped) andcompletion::Completer(waking when allCompletionobservers are dropped).watch::Senderandbroadcast::mpmcsenders remain excluded becausesubscribecan recreate receivers after the count reaches zero.Design Notes
mpsc,mpmc, andspmc) storedisconnect_waiters: WakerSetunder each channel's existing state lock rather than introducing a second lock or shared close-event type, keeping unused channels allocation-free and waking disconnect waiters before dropping buffered payloads.oneshot::Channel<T>lazily initializesdisconnect: OnceLock<Option<Arc<DisconnectWaiters>>>, avoiding heap allocation whendisconnected()is unused and avoiding extra raw-pointerunsafe. Receiver teardown sealsOnceLockand clones an ownedArcbefore publishingDISCONNECTEDand releasingChannel<T>; a concurrentpollobserving the seal window yields viawake_by_ref()andPoll::Pendingwithout spinning.completion::Shared<T>packsDISCONNECT_WAITERS_BITintoobservers: AtomicUsizeand storesOption<Arc<Shared<T>>>inCompleter<T>(preserving its pointer-sized niche layout andis_disconnected()linearizability). NormalCompletion::dropremains lock-free whendisconnected()has not been polled, lockingwaitersonly on the cold transition that drops the final observer withDISCONNECT_WAITERS_BITset.Validation:
cargo x lint,cargo x check,cargo x test, Miri (-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check), and MSRV (1.86.0).Fixes #467