Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.concurrency

Avoid blocking thread sleep in async functions

std::thread::sleep blocks the executor thread inside async code.

#Metadata

Rule ID
rust.correctness.thread-sleep-in-async
Severity
medium
Confidence
0.85
Languages
rust
Presets
strict
Stability
stable
Applies to
block
Tags
concurrency, correctness, rules-catalog, rust

#Why it matters

`std::thread::sleep` blocks the current OS thread. Inside `async fn` this stalls the runtime worker and harms throughput. Prefer `tokio::time::sleep` instead.

#Remediation

Use `tokio::time::sleep` or move blocking work to `spawn_blocking`.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/rust/rust.correctness.thread-sleep-in-async.rule.yaml.