summaryrefslogtreecommitdiff
path: root/examples/recv_timeout_before_send.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/recv_timeout_before_send.rs')
-rw-r--r--examples/recv_timeout_before_send.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/recv_timeout_before_send.rs b/examples/recv_timeout_before_send.rs
new file mode 100644
index 0000000..85a2ac8
--- /dev/null
+++ b/examples/recv_timeout_before_send.rs
@@ -0,0 +1,18 @@
+#[cfg(feature = "std")]
+fn main() {
+ use std::thread;
+ use std::time::Duration;
+
+ let (sender, receiver) = oneshot::channel();
+ let t = thread::spawn(move || {
+ thread::sleep(Duration::from_millis(2));
+ sender.send(9u128).unwrap();
+ });
+ assert_eq!(receiver.recv_timeout(Duration::from_millis(100)), Ok(9));
+ t.join().unwrap();
+}
+
+#[cfg(not(feature = "std"))]
+fn main() {
+ panic!("This example is only for when the \"sync\" feature is used");
+}