@@ -289,14 +289,30 @@ impl<T> Reader<T> {
289
289
/// If [`Reader::has_changed`] would already return `true` without blocking, this method will
290
290
/// return immediately.
291
291
pub fn block_until_changed ( & self ) {
292
+ self . block_until_changed_impl ( None ) ;
293
+ }
294
+
295
+ /// Blocks the calling thread until [`Reader::has_changed`] becomes `true`, or a timeout
296
+ /// elapses.
297
+ ///
298
+ /// If [`Reader::has_changed`] would already return `true` without blocking, this method will
299
+ /// return immediately.
300
+ pub fn block_until_changed_timeout ( & self , timeout : Duration ) {
301
+ self . block_until_changed_impl ( Some ( timeout) ) ;
302
+ }
303
+
304
+ fn block_until_changed_impl ( & self , timeout : Option < Duration > ) {
292
305
let mut guard = self . shared . inner . lock ( ) ;
293
306
loop {
294
307
if guard. generation != self . read_gen
295
308
|| self . shared . disconnected ( ) != self . read_disconnected
296
309
{
297
310
return ;
298
311
}
299
- guard = self . shared . condvar . wait ( guard) ;
312
+ guard = match timeout {
313
+ Some ( timeout) => self . shared . condvar . wait_timeout ( guard, timeout) . 0 ,
314
+ None => self . shared . condvar . wait ( guard) ,
315
+ } ;
300
316
}
301
317
}
302
318
@@ -307,6 +323,7 @@ impl<T> Reader<T> {
307
323
pub fn is_disconnected ( & self ) -> bool {
308
324
self . shared . disconnected ( )
309
325
}
326
+
310
327
/// Retrieves the current value.
311
328
///
312
329
/// If all associated [`Value`]s have been dropped, a [`Disconnected`] error is returned
0 commit comments