I tried this code:
use std::sync::mpsc::{self};
use std::mem;
fn main() {
let (sync_send, sync_recv) = mpsc::sync_channel(1);
sync_send.send(()).unwrap();
mem::drop(sync_send);
println!("{:?}", sync_recv.try_recv());
//-----------------------------------------//
let (send, recv) = mpsc::channel();
send.send(()).unwrap();
mem::drop(send);
println!("{:?}", recv.try_recv());
}
I expected to see this happen:
Instead, this happened:
Notes
I see that in the docs there is a comment under the Receiver::recv() method that states "However, since channels are buffered, messages sent before the disconnect will still be properly received." but this comment is not duplicated under Receiver::try_recv().
However, I tried tracing the specific Receiver used in conjunction with SyncSenders which led me to here where it looks like an eager check for a disconnect while ignoring possible data that is still buffered in the Queue. Is this intended?
I tried this code:
I expected to see this happen:
Instead, this happened:
Notes
I see that in the docs there is a comment under the
Receiver::recv()method that states "However, since channels are buffered, messages sent before the disconnect will still be properly received." but this comment is not duplicated underReceiver::try_recv().However, I tried tracing the specific
Receiverused in conjunction withSyncSenders which led me to here where it looks like an eager check for a disconnect while ignoring possible data that is still buffered in theQueue. Is this intended?