Skip to content

Commit a54d11f

Browse files
authored
Rollup merge of rust-lang#72141 - kornelski:dontsleep, r=joshtriplett
Warn against thread::sleep in async fn I've seen `thread::sleep` wrecking havoc in async servers. There's already an [issue for clippy](rust-lang/rust-clippy#4377), but the std docs could warn against it too.
2 parents 014ea51 + 2d39f5a commit a54d11f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libstd/thread/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ pub fn panicking() -> bool {
737737
/// The thread may sleep longer than the duration specified due to scheduling
738738
/// specifics or platform-dependent functionality. It will never sleep less.
739739
///
740+
/// This function is blocking, and should not be used in `async` functions.
741+
///
740742
/// # Platform-specific behavior
741743
///
742744
/// On Unix platforms, the underlying syscall may be interrupted by a
@@ -763,6 +765,8 @@ pub fn sleep_ms(ms: u32) {
763765
/// The thread may sleep longer than the duration specified due to scheduling
764766
/// specifics or platform-dependent functionality. It will never sleep less.
765767
///
768+
/// This function is blocking, and should not be used in `async` functions.
769+
///
766770
/// # Platform-specific behavior
767771
///
768772
/// On Unix platforms, the underlying syscall may be interrupted by a

0 commit comments

Comments
 (0)