File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -585,14 +585,24 @@ extension_trait! {
585585 #
586586 use async_std::prelude::*;
587587 use async_std::stream;
588- use std::time::Duration;
588+ use std::time::{ Duration, Instant} ;
589589
590+ let start = Instant::now();
590591 let mut s = stream::from_iter(vec![0u8, 1, 2]).delay(Duration::from_millis(200));
591592
592593 assert_eq!(s.next().await, Some(0));
594+ // The first time will take more than 200ms due to delay.
595+ assert!(start.elapsed().as_millis() >= 200);
596+
593597 assert_eq!(s.next().await, Some(1));
598+ // There will be no delay after the first time.
599+ assert!(start.elapsed().as_millis() <= 210);
600+
594601 assert_eq!(s.next().await, Some(2));
602+ assert!(start.elapsed().as_millis() <= 210);
603+
595604 assert_eq!(s.next().await, None);
605+ assert!(start.elapsed().as_millis() <= 210);
596606 #
597607 # }) }
598608 ```
You can’t perform that action at this time.
0 commit comments