Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace std::thread::sleep with tokio::time::sleep in async functions #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading