1
Fork 0

Rollup merge of #110056 - chenyukang:yukang/fix-110045, r=workingjubilee

Fix the example in document for WaitTimeoutResult::timed_out

Fixes #110045
This commit is contained in:
Matthias Krüger 2023-07-30 14:25:08 +02:00 committed by GitHub
commit e517ee02b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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