• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[test]
panic_in_the_middle_of_the_stream()2 fn panic_in_the_middle_of_the_stream() {
3     use futures::executor::block_on_stream;
4     use futures::stream::{self, StreamExt};
5 
6     let stream = stream::iter(vec![Some(10), None, Some(11)]);
7 
8     // panic on second element
9     let stream_panicking = stream.map(|o| o.unwrap());
10     let mut iter = block_on_stream(stream_panicking.catch_unwind());
11 
12     assert_eq!(10, iter.next().unwrap().ok().unwrap());
13     assert!(iter.next().unwrap().is_err());
14     assert!(iter.next().is_none());
15 }
16 
17 #[test]
no_panic()18 fn no_panic() {
19     use futures::executor::block_on_stream;
20     use futures::stream::{self, StreamExt};
21 
22     let stream = stream::iter(vec![10, 11, 12]);
23 
24     let mut iter = block_on_stream(stream.catch_unwind());
25 
26     assert_eq!(10, iter.next().unwrap().ok().unwrap());
27     assert_eq!(11, iter.next().unwrap().ok().unwrap());
28     assert_eq!(12, iter.next().unwrap().ok().unwrap());
29     assert!(iter.next().is_none());
30 }
31