-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathidle.rs
38 lines (32 loc) · 906 Bytes
/
idle.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use eventuals::*;
use std::time::{Duration, Instant};
use tokio::test;
use tokio::time::sleep;
#[test]
async fn never_idle_in_map() {
let (mut writer, reader) = Eventual::<u8>::new();
let mapped = reader.subscribe().map(|_v| async move {
idle().await;
panic!("Past idle");
});
writer.write(1);
// The panic should not be hit.
sleep(Duration::from_millis(10)).await;
// We can still drop the map, which should make the pipeline idle.
drop(mapped);
idle().await;
}
#[test]
async fn idle_after_map() {
let duration = Duration::from_millis(10);
idle().await;
let start = Instant::now();
let mapped = Eventual::from_value(5).map(move |v| async move {
sleep(duration).await;
v
});
idle().await;
assert!(Instant::now() - start > duration);
assert_eq!(mapped.value_immediate(), Some(5));
drop(mapped);
}