Repository navigation
Conversation
…der and completion::Completer
biaoma-ty
force-pushed
the
feat/sender-disconnected
branch
from
December 3, 2026 06:37
c82cd46 to
9edb13e
Compare
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), and relaxoneshot::Sender<T>to implementSyncunconditionally.watch::Senderandbroadcast::mpmcsenders remain excluded becausesubscribecan recreate receivers after the count reaches zero.Design Notes
mpsc,mpmc, andspmc) storedisconnect_waiters: Option<Box<WakerSet>>under each channel's existing state lock rather than introducing a second lock or shared close-event type, keeping idle channels allocation-free with minimal inline overhead 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. Relaxingoneshot::Sender<T>to unconditionalSync(sound because&Sender<T>never accesses or dropsT) letsDisconnectedborrow&Sender<T>directly without a duplicateNonNullorunsafe impl Send.completion::Shared<T>packsDISCONNECT_WAITERS_BITintoobservers: AtomicUsize(with half-range overflow headroom inCompletion::clone), storesdisconnect: Option<Box<WakerSet>>underwaiters, and holdsOption<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, andDisconnected::pollskipsfetch_oronce the bit is already set.Validation:
cargo x lint,cargo x check,cargo x test,cargo x semver --release-version 0.8.2, Miri (-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check), and MSRV (1.86.0).Fixes #467