Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akiradeveloper/da5d67833ea14eae18131c4f736664fd to your computer and use it in GitHub Desktop.
Save akiradeveloper/da5d67833ea14eae18131c4f736664fd to your computer and use it in GitHub Desktop.
stream that includes panicking future
#[tokio::test(flavor = "multi_thread")]
async fn test_buffered_unordered() {
use futures::FutureExt;
let mut futs = vec![];
futs.push(async move { 1 / 0 }.boxed());
for i in 1..=10 {
futs.push(async move { i }.boxed())
}
let stream = futures::stream::iter(futs);
let mut buffered = stream.buffer_unordered(100);
// My expection is only those completed in success are summed up
// ignoring the one that panicked.
let mut sum = 0;
while let Some(x) = buffered.next().await {
sum += x;
}
assert_eq!(sum, 55);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment