@@ -178,7 +178,7 @@ use crate::sys_common::thread;
178
178
use crate :: sys_common:: thread_info;
179
179
use crate :: sys_common:: thread_parking:: Parker ;
180
180
use crate :: sys_common:: { AsInner , IntoInner } ;
181
- use crate :: time:: Duration ;
181
+ use crate :: time:: { Duration , Instant } ;
182
182
183
183
#[ stable( feature = "scoped_threads" , since = "1.63.0" ) ]
184
184
mod scoped;
@@ -882,14 +882,14 @@ pub fn sleep(dur: Duration) {
882
882
///
883
883
/// # Platform-specific behavior
884
884
///
885
- /// This function uses [' sleep' ] internally, see its platform-specific behaviour.
885
+ /// This function uses [` sleep` ] internally, see its platform-specific behaviour.
886
886
///
887
887
///
888
888
/// # Examples
889
889
///
890
890
/// A simple game loop that limits the game to 60 frames per second.
891
891
///
892
- /// ''' no_run
892
+ /// ``` no_run
893
893
/// # use std::time::{Duration, Instant};
894
894
/// # use std::thread;
895
895
/// #
@@ -905,7 +905,7 @@ pub fn sleep(dur: Duration) {
905
905
/// update();
906
906
/// render();
907
907
/// }
908
- /// '''
908
+ /// ```
909
909
///
910
910
/// A slow api we must not call too fast and which takes a few
911
911
/// tries before succeeding. By using `sleep_until` the time the
@@ -915,31 +915,38 @@ pub fn sleep(dur: Duration) {
915
915
/// # use std::time::{Duration, Instant};
916
916
/// # use std::thread;
917
917
/// #
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) }
919
923
/// #
920
924
/// # const MAX_DURATION: Duration = Duration::from_secs(10);
921
925
/// #
926
+ /// # fn try_api_call() -> Result<usize, ()> {
922
927
/// let deadline = Instant::now() + MAX_DURATION;
923
928
/// let delay = Duration::from_millis(250);
924
929
/// let mut next_attempt = Instant::now();
925
930
/// loop {
926
931
/// if Instant::now() > deadline {
927
932
/// break Err(());
928
933
/// }
929
- /// if let Ready(data) = slow_web_api_call() {
934
+ /// if let Status:: Ready(data) = slow_web_api_call() {
930
935
/// break Ok(data);
931
936
/// }
932
937
///
933
938
/// next_attempt = deadline.min(next_attempt + delay);
934
939
/// thread::sleep_until(next_attempt);
935
940
/// }
941
+ /// # }
942
+ /// # let _data = try_api_call();
936
943
/// ```
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 ) {
939
946
let now = Instant :: now ( ) ;
940
947
941
948
if let Some ( delay) = deadline. checked_duration_since ( now) {
942
- thread :: sleep ( delay) ;
949
+ sleep ( delay) ;
943
950
}
944
951
}
945
952
0 commit comments