@@ -21,11 +21,11 @@ impl WaitTimeoutResult {
21
21
///
22
22
/// # Examples
23
23
///
24
- /// This example spawns a thread which will update the boolean value and
25
- /// then wait 100 milliseconds before notifying the condvar.
24
+ /// This example spawns a thread which will sleep 20 milliseconds before
25
+ /// updating a boolean value and then notifying the condvar.
26
26
///
27
- /// The main thread will wait with a timeout on the condvar and then leave
28
- /// once the boolean has been updated and notified .
27
+ /// The main thread will wait with a 10 millisecond timeout on the condvar
28
+ /// and will leave the loop upon timeout .
29
29
///
30
30
/// ```
31
31
/// use std::sync::{Arc, Condvar, Mutex};
@@ -49,14 +49,12 @@ impl WaitTimeoutResult {
49
49
///
50
50
/// // Wait for the thread to start up.
51
51
/// let (lock, cvar) = &*pair;
52
- /// let mut started = lock.lock().unwrap();
53
52
/// loop {
54
53
/// // Let's put a timeout on the condvar's wait.
55
- /// let result = cvar.wait_timeout(started, Duration::from_millis(10)).unwrap();
56
- /// // 10 milliseconds have passed, or maybe the value changed!
57
- /// started = result.0;
58
- /// if *started == true {
59
- /// // We received the notification and the value has been updated, we can leave.
54
+ /// let result = cvar.wait_timeout(lock.lock().unwrap(), Duration::from_millis(10)).unwrap();
55
+ /// // 10 milliseconds have passed.
56
+ /// if result.1.timed_out() {
57
+ /// // timed out now and we can leave.
60
58
/// break
61
59
/// }
62
60
/// }
0 commit comments