1
Fork 0

Auto merge of #23330 - alexcrichton:thread-sleep, r=aturon

This function is the current replacement for `std::old_io::timer` which will
soon be deprecated. This function is unstable and has its own feature gate as it
does not yet have an RFC nor has it existed for very long.
This commit is contained in:
bors 2015-03-17 17:15:54 +00:00
commit bfac337daa
4 changed files with 197 additions and 221 deletions

View file

@ -379,6 +379,19 @@ pub fn panicking() -> bool {
unwind::panicking()
}
/// Put the current thread to sleep for the specified amount of time.
///
/// The thread may sleep longer than the duration specified due to scheduling
/// specifics or platform-dependent functionality. Note that on unix platforms
/// this function will not return early due to a signal being received or a
/// spurious wakeup.
#[unstable(feature = "thread_sleep",
reason = "recently added, needs an RFC, and `Duration` itself is \
unstable")]
pub fn sleep(dur: Duration) {
imp::sleep(dur)
}
/// Block unless or until the current thread's token is made available (may wake spuriously).
///
/// See the module doc for more detail.
@ -935,6 +948,12 @@ mod test {
}
}
#[test]
fn sleep_smoke() {
thread::sleep(Duration::milliseconds(2));
thread::sleep(Duration::milliseconds(-2));
}
// NOTE: the corresponding test for stderr is in run-pass/task-stderr, due
// to the test harness apparently interfering with stderr configuration.
}