diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-23 14:29:39 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-23 14:29:39 +0300 |
commit | 899788965322863f45d601f9ae6a132535f4e557 (patch) | |
tree | 4ed9da40a65e784eee081e7b12010a64f99bdda8 | |
parent | d15605adea20a93214b678d30e73ca7bcbf1bc1b (diff) | |
download | summain-rs-899788965322863f45d601f9ae6a132535f4e557.tar.gz |
comment
-rw-r--r-- | src/bin/summain.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/bin/summain.rs b/src/bin/summain.rs index 6344298..5031006 100644 --- a/src/bin/summain.rs +++ b/src/bin/summain.rs @@ -8,11 +8,25 @@ async fn main() -> anyhow::Result<()> { let mut opt = Opt::from_args(); opt.pathnames[..].sort(); + // Get metadata about all files, but don't compute checksum yet. + // + // This all runs in async worker threads, since it's theoretically + // I/O heavy and benefits from async task context switching. We + // create a task for each named file, since tasks are very cheap. + // We keep the JoinHandle for each task in a vector: there's not + // going to be so many handles that the vector becomes impossibly + // large: Linux only allows 128 KiB of command line arguments. + let mut handles = vec![]; for filename in opt.pathnames.iter().cloned() { handles.push(tokio::spawn(async move { manifest(filename) })); } + // Compute checksums for regular files. + // + // This runs in blocking threads, since it's CPU heavy. We create + // another vector of JoinHandles. Again, it won't become too large. + let mut sumhandles = vec![]; for h in handles { let mut m: ManifestEntry = h.await?.await?; @@ -23,6 +37,10 @@ async fn main() -> anyhow::Result<()> { sumhandles.push(h) } + // Wait for checksums to be available and print manifest. + // + // Note how this iterates over the results in the right order. + for h in sumhandles { let m: ManifestEntry = h.await??; print!("{}", serde_yaml::to_string(&m)?); |