Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, there is no way to get the total capacity, remaining capacity, or used length of a MPSC channel. This PR adds the following methods to `mps::Sender`, `mpsc::Receiver`, `mpsc::StaticSender`, `mpsc::StaticReceiver`, and their `mpsc::blocking` equivalents: - `capacity`: Returns the total capacity of a channel, including used capacity. - `len`: Returns the number of messages currently in a channel. - `remaining`: Returns the current _free_ capacity of a channel (`capacity - len`). - `is_empty`: Returns `true` if there are no messages in a channel. Additionally, I've fixed a bug in `Core::len` where, if the channel is closed and contains zero messages, the length returned is equal to its capacity rather than 0. This is due to the `Core::len` function incorrectly testing whether `head == tail` without masking out the `closed` bit, which may be set in either `head` or `tail` when a channel closes. This causes us to believe a closed channel is full when it's actually empty. I've added tests reproducing this. Fixes #71 --------- Co-authored-by: Joel Crevier <[email protected]> Co-authored-by: Eliza Weisman <[email protected]>
- Loading branch information