Skip to content

Commit 84185d0

Browse files
committed
replace std::thread::sleep with tokio::time::sleep in async function
1 parent 41a134a commit 84185d0

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ num_cpus = "1.16.0"
2828
rlimit = "0.10.1"
2929
serde = { version = "1.0.188", features = ["serde_derive"] }
3030
serde_json = "1.0.107"
31-
tokio = { version = "1.32.0", features = ["full"] }
31+
tokio = { version = "1.36.0", features = ["full"] }
3232
itertools = "0.11.0"
3333
rand = "0.8.5"
3434
env_logger = "0.10.0"

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async fn main() -> Result<(), session::Error> {
103103

104104
let one_sec = time::Duration::from_secs(1);
105105
while !session.is_finished() {
106-
std::thread::sleep(one_sec);
106+
tokio::time::sleep(one_sec).await;
107107
}
108108

109109
log::info!("runtime {:?}", start.elapsed());

src/plugins/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async fn worker(
125125
.gen_range(session.options.jitter_min..=session.options.jitter_max);
126126
if ms > 0 {
127127
log::debug!("jitter of {} ms", ms);
128-
std::thread::sleep(time::Duration::from_millis(ms));
128+
tokio::time::sleep(time::Duration::from_millis(ms)).await;
129129
}
130130
}
131131

@@ -144,7 +144,7 @@ async fn worker(
144144
session.options.retries,
145145
err
146146
);
147-
std::thread::sleep(retry_time);
147+
tokio::time::sleep(retry_time).await;
148148
continue;
149149
} else {
150150
// add this target to the list of unreachable in order to avoi

src/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async fn periodic_saver(session: Arc<Session>) {
2727
let persistent = session.options.session.is_some();
2828

2929
while !session.is_stop() {
30-
std::thread::sleep(one_sec);
30+
tokio::time::sleep(one_sec).await;
3131

3232
// compute number of attempts per second
3333
let new_done = session.get_done();

0 commit comments

Comments
 (0)