From afabd8c6f9178a56c3e52289403df6f95889b80a Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Wed, 10 Feb 2021 10:29:17 -0800 Subject: [PATCH] Minor tokio cleanup --- Cargo.lock | 56 ------------------------------------------- Cargo.toml | 13 +++++++++- default.nix | 2 +- src/command/exec.rs | 4 ++-- src/main.rs | 2 +- src/nix/deployment.rs | 15 ++++++------ 6 files changed, 23 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7611e9..2596879 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,15 +335,6 @@ dependencies = [ "regex", ] -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "itoa" version = "0.4.6" @@ -362,15 +353,6 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" -[[package]] -name = "lock_api" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.11" @@ -452,31 +434,6 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -670,12 +627,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.118" @@ -722,12 +673,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -[[package]] -name = "smallvec" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" - [[package]] name = "snafu" version = "0.6.10" @@ -867,7 +812,6 @@ dependencies = [ "mio", "num_cpus", "once_cell", - "parking_lot", "pin-project-lite", "signal-hook-registry", "tokio-macros", diff --git a/Cargo.toml b/Cargo.toml index 5da210e..07e716d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,5 +25,16 @@ serde_json = "1.0" sys-info = "0.7.0" snafu = "0.6.10" tempfile = "3.1.0" -tokio = { version = "1.0.0", features = ["full"] } validator = { version = "0.12", features = ["derive"] } + +[dependencies.tokio] +version = "1.0.0" +features = [ + "fs", + "io-util", + "macros", + "process", + "rt", + "rt-multi-thread", + "sync", +] diff --git a/default.nix b/default.nix index 87d7b21..00ecbc9 100644 --- a/default.nix +++ b/default.nix @@ -14,5 +14,5 @@ in rustPlatform.buildRustPackage { src = ./.; }; }; - cargoSha256 = "0imalrw8im6zl5lq8k5j05msykax85lya39vq0fxagifdckcdfsb"; + cargoSha256 = "1ibhn8bbcx0y9gjl42d9ba478j6a5dr928v0ds61vwn7lbm68dzr"; } diff --git a/src/command/exec.rs b/src/command/exec.rs index 69c518f..828f406 100644 --- a/src/command/exec.rs +++ b/src/command/exec.rs @@ -139,7 +139,7 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { let command = command.clone(); let progress = progress.clone(); - futures.push(tokio::spawn(async move { + futures.push(async move { let permit = match parallel_sp.as_ref() { Some(sp) => Some(sp.acquire().await.unwrap()), None => None, @@ -166,7 +166,7 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { } drop(permit); - })); + }); } join_all(futures).await; diff --git a/src/main.rs b/src/main.rs index 102a087..e644617 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ macro_rules! bind_command { }; } -#[tokio::main(flavor = "multi_thread")] +#[tokio::main] async fn main() { init_logging(); diff --git a/src/nix/deployment.rs b/src/nix/deployment.rs index 3f27160..c6afeb5 100644 --- a/src/nix/deployment.rs +++ b/src/nix/deployment.rs @@ -274,8 +274,7 @@ impl Deployment { let arc_self = self.clone(); let progress = progress.clone(); - // how come the bars show up only when initialized here??? - futures.push(tokio::spawn(async move { + futures.push(async move { let permit = arc_self.parallelism_limit.apply.acquire().await.unwrap(); let mut process = progress.create_process_progress(node.clone()); @@ -294,7 +293,7 @@ impl Deployment { } drop(permit); - })); + }); } join_all(futures).await @@ -334,7 +333,7 @@ impl Deployment { // FIXME: Eww let chunk: Vec = chunk.iter().map(|s| s.to_string()).collect(); - futures.push(tokio::spawn(async move { + futures.push(async move { let drv = { // Evaluation phase let permit = arc_self.parallelism_limit.evaluation.acquire().await.unwrap(); @@ -401,12 +400,12 @@ impl Deployment { let profile = profiles.get(&node).cloned() .expect(&format!("Somehow profile for {} was not built", node)); - futures.push(tokio::spawn(async move { + futures.push(async move { arc_self.apply_profile(&node, target, profile, progress).await - })); + }); } - - })); + join_all(futures).await; + }); } join_all(futures).await;