From 84185d0afecb2c64ae7afed37dae8c8dd6e88eae Mon Sep 17 00:00:00 2001 From: Dmitry Gasanyan Date: Tue, 5 Mar 2024 09:59:18 +0300 Subject: [PATCH] replace std::thread::sleep with tokio::time::sleep in async function --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/main.rs | 2 +- src/plugins/manager.rs | 4 ++-- src/session/mod.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54ab66c..e4f7e63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4559,9 +4559,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 15ece34..7f0ab7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ num_cpus = "1.16.0" rlimit = "0.10.1" serde = { version = "1.0.188", features = ["serde_derive"] } serde_json = "1.0.107" -tokio = { version = "1.32.0", features = ["full"] } +tokio = { version = "1.36.0", features = ["full"] } itertools = "0.11.0" rand = "0.8.5" env_logger = "0.10.0" diff --git a/src/main.rs b/src/main.rs index df230e3..092d08e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,7 +103,7 @@ async fn main() -> Result<(), session::Error> { let one_sec = time::Duration::from_secs(1); while !session.is_finished() { - std::thread::sleep(one_sec); + tokio::time::sleep(one_sec).await; } log::info!("runtime {:?}", start.elapsed()); diff --git a/src/plugins/manager.rs b/src/plugins/manager.rs index 760ec24..c462cfb 100644 --- a/src/plugins/manager.rs +++ b/src/plugins/manager.rs @@ -125,7 +125,7 @@ async fn worker( .gen_range(session.options.jitter_min..=session.options.jitter_max); if ms > 0 { log::debug!("jitter of {} ms", ms); - std::thread::sleep(time::Duration::from_millis(ms)); + tokio::time::sleep(time::Duration::from_millis(ms)).await; } } @@ -144,7 +144,7 @@ async fn worker( session.options.retries, err ); - std::thread::sleep(retry_time); + tokio::time::sleep(retry_time).await; continue; } else { // add this target to the list of unreachable in order to avoi diff --git a/src/session/mod.rs b/src/session/mod.rs index bccdecd..adc2ecd 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -27,7 +27,7 @@ async fn periodic_saver(session: Arc) { let persistent = session.options.session.is_some(); while !session.is_stop() { - std::thread::sleep(one_sec); + tokio::time::sleep(one_sec).await; // compute number of attempts per second let new_done = session.get_done();