Skip to content

feat(channel): add is_disconnected to mpsc and mpmc endpoints - #391

Merged
tisonkun merged 1 commit into
apache:mainfrom
FalkWoldmann:channel-is-disconnected
Nov 1, 2026
Merged

tisonkun merged 1 commit into
apache:mainfrom
FalkWoldmann:channel-is-disconnected

Conversation

@FalkWoldmann

Copy link
Copy Markdown
Contributor

Summary

Closes #377.

Adds is_disconnected to the mpsc and mpmc senders and receivers, so callers can tell whether the other side is gone without sending or receiving. A sender reports true once the last receiver is dropped. A receiver reports true once the last sender is dropped, even while queued messages are still receivable, same as watch. I left the spmc endpoints out to keep this small, happy to add them in a follow-up if you want them

@tisonkun
tisonkun requested review from ariesdevil and a balanced review from Copilot November 1, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the new channel disconnection checks.

No open issues 🎉

What changed in this PR

Adds is_disconnected to bounded and unbounded mpsc and mpmc endpoints, addressing #377 and aligning these channels with existing oneshot and watch APIs.

Changes:

  • Exposes connection-state checks without sending or receiving.
  • Documents that receivers report disconnection after the last sender drops, even while buffered messages remain readable.
  • Adds examples, integration tests for endpoint drops and clone counts, and a changelog entry.
File Description
tests-integration/​tests/​mpsc_test/​main.rs Tests disconnection, reserved permits, and buffered-message draining.
tests-integration/​tests/​mpmc_test/​main.rs Tests clone-aware disconnection, permits, and buffered messages.
CHANGELOG.md Announces the new methods and receiver semantics.
asyncband/​src/​mpsc/​unbounded/​sender.rs Adds the sender check with documentation and an example.
asyncband/​src/​mpsc/​unbounded/​receiver.rs Adds the receiver check independent of queued messages.
asyncband/​src/​mpsc/​bounded/​sender.rs Adds the sender check and documents permit behavior.
asyncband/​src/​mpsc/​bounded/​receiver.rs Adds the receiver check with buffered-message semantics.
asyncband/​src/​mpmc/​unbounded.rs Adds documented checks to both unbounded endpoints.
asyncband/​src/​mpmc/​queue.rs Adds shared sender- and receiver-count queries.
asyncband/​src/​mpmc/​bounded.rs Adds documented checks to both bounded endpoints.

Review effort: Balanced

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! LGTM.

I'll merge this tomorrow if there is no more comment.

@tisonkun

tisonkun commented Nov 1, 2026

Copy link
Copy Markdown
Member

Could you share a concrete use case where is_disconnected is useful beyond calling try_recv or recv and handling the disconnection error? That would usually be sufficient for a consumer. The separate check acquires the internal mutex, and its semantics are a little subtle: false can become outdated immediately, while true on a receiver still allows buffered messages to be received. An example of how you intend to use this method would help us understand when the additional query is worth exposing.

@FalkWoldmann

Copy link
Copy Markdown
Contributor Author

The need is on the sender side, where there is nothing like try_recv to fall back on: an unbounded sender learns the receiver is gone only by sending something, and try_reserve on a bounded one takes a slot to find out. compio-actor's mailbox defines is_closed() as stopping || messages.is_disconnected() || stop.is_disconnected(), so a handle can tell whether the actor still takes messages without sending one. In maki, a TUI coding agent I work on, the plugin host prunes dead window handles with windows.retain(|tx| !tx.is_disconnected()), refuses a UI action before it starts when nothing is draining the event loop's channel, and skips an image encode when the requester went away. On the receiver side I only use it in tests, to wait for the producer to drop without consuming its messages. I can make it sender-only if you'd rather not expose the receiver variant

@tisonkun

tisonkun commented Nov 1, 2026

Copy link
Copy Markdown
Member

Thanks for sharing. The current shape is good.

@tisonkun
tisonkun merged commit b2015b0 into apache:main Nov 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add is_disconnected to the mpsc and mpmc endpoints

3 participants