Closed
Description
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:
Ok(())
Ok(())
Instead, this happened:
Err(Disconnected)
Ok(())
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 SyncSender
s 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?
Metadata
Metadata
Assignees
Labels
No labels