From edc17508e1ac77b9a5c54a48f65db5298695cd39 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 8 Mar 2020 16:49:04 +0000 Subject: [PATCH] Only write every so often --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 96711f5..5d67924 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,6 +261,8 @@ async fn main() -> Result<(), Error> { } fs::write("results/results.yaml", serde_yaml::to_string(&results)?)?; + let mut not_written = 0; + let mut last_written = Local::now(); while url_checks.len() > 0 { debug!("Waiting..."); let ((url, res), _index, remaining) = select_all(url_checks).await; @@ -324,8 +326,16 @@ async fn main() -> Result<(), Error> { } } std::io::stdout().flush().unwrap(); - fs::write("results/results.yaml", serde_yaml::to_string(&results)?)?; + + not_written += 1; + let duration = Local::now() - last_written; + if duration > Duration::seconds(5) || not_written > 20 { + fs::write("results/results.yaml", serde_yaml::to_string(&results)?)?; + not_written = 0; + last_written = Local::now(); + } } + fs::write("results/results.yaml", serde_yaml::to_string(&results)?)?; println!(""); let mut failed: u32 = 0;