Repository navigation
Conversation
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
Closes #312.
recvandtry_recvon both broadcast MPMC receivers now return the channel's ownArc<T>, andboundedandunboundedno longer requireT: Clone. A message fanned out to N subscribers is one allocation shared N times, with noT::cloneanywhere. Callers that want an ownedTuse the newrecv_clonedandtry_recv_cloned, which keep today's behavior of moving the payload out instead of cloning it when the receiver ends up with the only reference.This is a breaking change. Existing callers either switch to
recv_clonedor deref theArc, and the changelog says so under Breaking changes.cargo x semverdoes not flag it, because cargo-semver-checks has no lint for a changed return type on an inherent method, so the changelog entry is the only record.An
Arckept past the receive keeps the payload alive after the message leaves the backlog, so bounded capacity still limits retained messages rather than memory. That was already the case for cloned values.Design Notes
The channel already stores every message behind an
Arcso that cloning and dropping payloads happens outside the lock, and nothing under the lock changes here. The only change is the step after the lock is released.take_msgis split intoshare_msg, which releases the backlog's reference and hands out the storedArc, and the existingtake_msg, which still decides ownership from the reclaim bookkeeping instead of probing the reference count and now falls back throughArc::unwrap_or_clone. AnArckept from another subscriber'srecvis a new reason for that fallback to clone, and a test checks it clones exactly once in that case.Each channel's private
Recvfuture now yields the received pair and the four public methods wrap it, so registration, cancellation and the drop path are the same code forrecvandrecv_cloned. In the bounded channel the capacity release still happens beforetake_msgcan runT::clone, so a panicking clone cannot strand a blocked producer. A test parks asend, panics insiderecv_cloned, and checks the producer is woken. The shared path runs no user code at all, since a receive reclaims at most the message itself and the returnedArckeeps it alive.The ecosystem benchmarks use the cloned variants so the comparison with tokio and async-broadcast, which return owned values, stays fair.
broadcast/spmcis untouched because #317 is adding it.