Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document MPMC behavior #42

Closed
schell opened this issue Oct 13, 2021 · 2 comments
Closed

Document MPMC behavior #42

schell opened this issue Oct 13, 2021 · 2 comments

Comments

@schell
Copy link

schell commented Oct 13, 2021

I was surprised to find that cloning a Receiver and sending a message on the connected Sender results in the message showing up at only one of the downstream Receivers, but not both. Sending more messages results in a round-robin of sorts, where the Receiver next in line awaiting recv will get the next message.

This doesn't seem to be the implied MPMC behavior, though I'm not an authority on the matter.

Here's a minimal example in the form of a failing test:

    #[test]
    fn channel_sanity() {
        let (tx, rx1) = async_channel::unbounded::<u32>();
        let rx2 = rx1.clone();
        let t1 = smol::spawn(async move {
            let n = rx2.recv().await.unwrap();
            assert_eq!(n, 666);
        });
        let t2 =
            smol::spawn(async move {
            let n = rx1.recv().await.unwrap();
            assert_eq!(n, 666);
        });

        smol::block_on(async move {
            tx.send(666).await.unwrap();
            tx.send(123).await.unwrap();
            let ((), ()) = futures::future::join(t1, t2).await;
        });
    }
@taiki-e
Copy link
Collaborator

taiki-e commented Oct 13, 2021

@taiki-e taiki-e closed this as completed Oct 13, 2021
@schell
Copy link
Author

schell commented Oct 13, 2021

Ah, I see. I missed that update. Thanks for the clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants