Minor tokio cleanup

This commit is contained in:
Zhaofeng Li 2021-02-10 10:29:17 -08:00
parent 9f4d5a2221
commit afabd8c6f9
6 changed files with 23 additions and 69 deletions

56
Cargo.lock generated
View file

@ -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",

View file

@ -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",
]

View file

@ -14,5 +14,5 @@ in rustPlatform.buildRustPackage {
src = ./.;
};
};
cargoSha256 = "0imalrw8im6zl5lq8k5j05msykax85lya39vq0fxagifdckcdfsb";
cargoSha256 = "1ibhn8bbcx0y9gjl42d9ba478j6a5dr928v0ds61vwn7lbm68dzr";
}

View file

@ -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;

View file

@ -27,7 +27,7 @@ macro_rules! bind_command {
};
}
#[tokio::main(flavor = "multi_thread")]
#[tokio::main]
async fn main() {
init_logging();

View file

@ -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<String> = 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;