-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Description
If you close the rx side of a channel pair before sending to it, then the first send will fail with a SendError as expected, but a second send will return Ok(()).
use std::sync::mpsc::{channel, SendError};
#[test]
fn doublesend() {
let (tx, _) = channel();
assert_eq!(tx.send(123), Ok(()));
assert_eq!(tx.send(123), Err(SendError(123)));
assert_eq!(tx.send(123), Err(SendError(123)));
}Fails with:
thread 'doublesend' panicked at 'assertion failed:
(left == right)(left:Err("SendError(..)"), right:Ok(()))', :7
However, if something is successfully sent before the receiver is dropped (even if it never receives the value), then it works as expected:
use std::sync::mpsc::{channel, SendError};
use std::mem;
#[test]
fn doublesend() {
let (tx, rx) = channel();
assert_eq!(tx.send(123), Ok(()));
mem::drop(rx);
assert_eq!(tx.send(123), Err(SendError(123)));
assert_eq!(tx.send(123), Err(SendError(123)));
}Metadata
Metadata
Assignees
Labels
No labels