mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
add SyncSender::send_timeout
test
This commit is contained in:
parent
2538c0c170
commit
f8276c94ac
@ -43,7 +43,7 @@ mod zero;
|
||||
use crate::fmt;
|
||||
use crate::panic::{RefUnwindSafe, UnwindSafe};
|
||||
use crate::time::{Duration, Instant};
|
||||
use error::*;
|
||||
pub use error::*;
|
||||
|
||||
/// Creates a channel of unbounded capacity.
|
||||
///
|
||||
|
@ -738,6 +738,15 @@ impl<T> SyncSender<T> {
|
||||
pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>> {
|
||||
self.inner.try_send(t)
|
||||
}
|
||||
|
||||
// Attempts to send for a value on this receiver, returning an error if the
|
||||
// corresponding channel has hung up, or if it waits more than `timeout`.
|
||||
//
|
||||
// This method is currently private and only used for tests.
|
||||
#[allow(unused)]
|
||||
fn send_timeout(&self, t: T, timeout: Duration) -> Result<(), mpmc::SendTimeoutError<T>> {
|
||||
self.inner.send_timeout(t, timeout)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use crate::env;
|
||||
use crate::sync::mpmc::SendTimeoutError;
|
||||
use crate::thread;
|
||||
use crate::time::Duration;
|
||||
|
||||
@ -41,6 +42,13 @@ fn recv_timeout() {
|
||||
assert_eq!(rx.recv_timeout(Duration::from_millis(1)), Ok(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_timeout() {
|
||||
let (tx, _rx) = sync_channel::<i32>(1);
|
||||
assert_eq!(tx.send_timeout(1, Duration::from_millis(1)), Ok(()));
|
||||
assert_eq!(tx.send_timeout(1, Duration::from_millis(1)), Err(SendTimeoutError::Timeout(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_threads() {
|
||||
let (tx, rx) = sync_channel::<i32>(0);
|
||||
|
Loading…
Reference in New Issue
Block a user