Repository navigation
feat(channel): add is_empty to mpsc and mpmc receivers - #392
Conversation
tisonkun
left a comment
There was a problem hiding this comment.
I think it's generally OK to add an is_empty method, but I wonder the necessity to have a len merge?
Could you provide some more background on how other ecosystem libraries do it?
There was a problem hiding this comment.
🟡 Changes recommended
Length and emptiness checks scan every sealed segment under the shared mutex, causing quadratic work when draining large payloads and blocking senders unnecessarily.
1 open issue
What changed in this PR
Adds receiver-side len and is_empty APIs to bounded and unbounded mpsc and mpmc channels, following the endpoint inspection work in #377.
Changes:
- Counts queued, unreceived values while excluding held permits and sends waiting for capacity.
- Includes receiver-local batches in unbounded mpsc counts.
- Adds API examples, integration tests, and a changelog entry.
| File | Description |
|---|---|
tests-integration/tests/mpsc_test/main.rs |
Tests reservations, blocked sends, local batches, and draining. |
tests-integration/tests/mpmc_test/main.rs |
Tests queue counts across receiver clones and disconnection. |
CHANGELOG.md |
Documents the new receiver APIs and counting semantics. |
asyncband/src/mpsc/unbounded/receiver.rs |
Adds observations covering local and shared buffers. |
asyncband/src/mpsc/unbounded/buffer.rs |
Adds buffer length calculation and assertions. |
asyncband/src/mpsc/bounded/receiver.rs |
Adds documented queue length and emptiness APIs. |
asyncband/src/mpmc/unbounded.rs |
Exposes documented observations through shared state. |
asyncband/src/mpmc/queue.rs |
Adds shared queue length and emptiness helpers. |
asyncband/src/mpmc/bounded.rs |
Exposes observations excluding capacity reservations. |
Review effort: Balanced
|
Fair. The concrete need I have is |
|
Thanks for the context! Keeping the surface minimal makes sense here. I'd prefer to drop
|
tisonkun
left a comment
There was a problem hiding this comment.
@FalkWoldmann You may resolve the conflict so I can merge it later.
I can resolve them myself anyway when it comes to me next time :D
4bb9910 to
8f8b940
Compare
|
Dropped |
orthur2
left a comment
There was a problem hiding this comment.
Thanks, looks good to me.

Summary
Follow-up to #377. Adds
is_emptyto the mpsc and mpmc receivers, so an event loop can check for queued values without receiving. Held permits and sends still waiting for capacity don't count. I kept it on the receivers only, like tokio: the unbounded mpsc receiver holds a local batch the senders can't see, so a sender-side check would be off there