@@ -178,7 +178,7 @@ use crate::sys_common::thread;
178178use crate :: sys_common:: thread_info;
179179use crate :: sys_common:: thread_parking:: Parker ;
180180use crate :: sys_common:: { AsInner , IntoInner } ;
181- use crate :: time:: Duration ;
181+ use crate :: time:: { Duration , Instant } ;
182182
183183#[ stable( feature = "scoped_threads" , since = "1.63.0" ) ]
184184mod scoped;
@@ -882,14 +882,14 @@ pub fn sleep(dur: Duration) {
882882///
883883/// # Platform-specific behavior
884884///
885- /// This function uses [' sleep' ] internally, see its platform-specific behaviour.
885+ /// This function uses [` sleep` ] internally, see its platform-specific behaviour.
886886///
887887///
888888/// # Examples
889889///
890890/// A simple game loop that limits the game to 60 frames per second.
891891///
892- /// ''' no_run
892+ /// ``` no_run
893893/// # use std::time::{Duration, Instant};
894894/// # use std::thread;
895895/// #
@@ -905,7 +905,7 @@ pub fn sleep(dur: Duration) {
905905/// update();
906906/// render();
907907/// }
908- /// '''
908+ /// ```
909909///
910910/// A slow api we must not call too fast and which takes a few
911911/// tries before succeeding. By using `sleep_until` the time the
@@ -915,31 +915,38 @@ pub fn sleep(dur: Duration) {
915915/// # use std::time::{Duration, Instant};
916916/// # use std::thread;
917917/// #
918- /// # fn slow_web_api_call() {}
918+ /// # enum Status {
919+ /// # Ready(usize),
920+ /// # Waiting,
921+ /// # }
922+ /// # fn slow_web_api_call() -> Status { Status::Ready(42) }
919923/// #
920924/// # const MAX_DURATION: Duration = Duration::from_secs(10);
921925/// #
926+ /// # fn try_api_call() -> Result<usize, ()> {
922927/// let deadline = Instant::now() + MAX_DURATION;
923928/// let delay = Duration::from_millis(250);
924929/// let mut next_attempt = Instant::now();
925930/// loop {
926931/// if Instant::now() > deadline {
927932/// break Err(());
928933/// }
929- /// if let Ready(data) = slow_web_api_call() {
934+ /// if let Status:: Ready(data) = slow_web_api_call() {
930935/// break Ok(data);
931936/// }
932937///
933938/// next_attempt = deadline.min(next_attempt + delay);
934939/// thread::sleep_until(next_attempt);
935940/// }
941+ /// # }
942+ /// # let _data = try_api_call();
936943/// ```
937- #[ unstable( feature = "thread_sleep_until" , issue = "todo " ) ]
938- pub fn sleep_untill ( deadline : Instant ) {
944+ #[ unstable( feature = "thread_sleep_until" , issue = "113752 " ) ]
945+ pub fn sleep_until ( deadline : Instant ) {
939946 let now = Instant :: now ( ) ;
940947
941948 if let Some ( delay) = deadline. checked_duration_since ( now) {
942- thread :: sleep ( delay) ;
949+ sleep ( delay) ;
943950 }
944951}
945952
0 commit comments