Skip to content

Commit

Permalink
Merge pull request #39 from dimtgsn/tokio-time-sleep-instead-of-std-t…
Browse files Browse the repository at this point in the history
…hread-sleep

replace std::thread::sleep with tokio::time::sleep in async functions
  • Loading branch information
evilsocket committed Mar 12, 2024
2 parents 41a134a + 84185d0 commit 071002b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn periodic_saver(session: Arc<Session>) {
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();
Expand Down

0 comments on commit 071002b

Please sign in to comment.