From f98dad7a3a19c9f731fd87c8b3c0e14e976d76d6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 7 Jun 2021 02:06:00 +0200 Subject: main: Collect errors from spawned tasks Collect all errors into a list. I think I'm going to return them as a list from this function. The runtime appears a lot slower with this change. Need to figure out what that's about. --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index a476ef0..0d4938d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use anyhow::{self, Context}; use chrono::DateTime; use exitcode; use filetime; -use futures::{self, executor, future}; +// use futures::{self, executor, future}; use getopts::Options; use parse_size::parse_size; use sqlx; @@ -137,16 +137,22 @@ fn run() -> anyhow::Result<()> { } // executor::block_on(future::join_all(joins)); - rt.block_on(async { - let mut joins = tokio_stream::iter(&joins); + let results = rt.block_on(async { + let mut joins = tokio_stream::iter(&mut joins); + let mut results = Vec::new(); while let Some(task) = joins.next().await { - let a = task.await?; - dbg!(a); + let result = task.await; + results.push(result); } - Ok::<(), anyhow::Error>(()) - })?; + results + }); + + let errors = results.iter() + .filter(|r| r.is_err()); + + dbg!(&errors); Ok(()) } -- cgit v1.2.3