@@ -277,7 +277,7 @@ impl<'conn> Notifications<'conn> {
277277 /// Returns the oldest pending notification
278278 ///
279279 /// If no notifications are pending, blocks for up to `timeout` time, after
280- /// which an `IoError` with the `TimedOut` kind is returned.
280+ /// which `None` is returned.
281281 ///
282282 /// ## Example
283283 ///
@@ -290,40 +290,40 @@ impl<'conn> Notifications<'conn> {
290290 ///
291291 /// # let conn = postgres::Connection::connect("", &postgres::SslMode::None).unwrap();
292292 /// match conn.notifications().next_block_for(Duration::seconds(2)) {
293- /// Ok(notification) => println!("notification: {}", notification.payload),
294- /// Err(Error::IoError(IoError { kind: IoErrorKind::TimedOut, .. })) => {
295- /// println!("Wait for notification timed out");
296- /// }
297- /// Err(e) => println!("Other error: {:?}", e),
293+ /// Some(Ok(notification)) => println!("notification: {}", notification.payload),
294+ /// Some(Err(e)) => println!("Error: {:?}", e),
295+ /// None => println!("Wait for notification timed out"),
298296 /// }
299297 /// ```
300- pub fn next_block_for ( & mut self , timeout : Duration ) -> Result < Notification > {
298+ pub fn next_block_for ( & mut self , timeout : Duration ) -> Option < Result < Notification > > {
301299 if let Some ( notification) = self . next ( ) {
302- return Ok ( notification) ;
300+ return Some ( Ok ( notification) ) ;
303301 }
304302
305303 let mut conn = self . conn . conn . borrow_mut ( ) ;
306- check_desync ! ( conn) ;
304+ if conn. desynchronized {
305+ return Some ( Err ( Error :: StreamDesynchronized ) ) ;
306+ }
307307
308308 let end = SteadyTime :: now ( ) + timeout;
309309 loop {
310310 let timeout = max ( Duration :: zero ( ) , end - SteadyTime :: now ( ) ) . num_milliseconds ( ) as u64 ;
311311 conn. stream . set_read_timeout ( Some ( timeout) ) ;
312312 match conn. read_one_message ( ) {
313313 Ok ( Some ( NotificationResponse { pid, channel, payload } ) ) => {
314- return Ok ( Notification {
314+ return Some ( Ok ( Notification {
315315 pid : pid,
316316 channel : channel,
317317 payload : payload
318- } )
318+ } ) )
319319 }
320320 Ok ( Some ( _) ) => unreachable ! ( ) ,
321321 Ok ( None ) => { }
322- Err ( e @ IoError { kind : IoErrorKind :: TimedOut , .. } ) => {
322+ Err ( IoError { kind : IoErrorKind :: TimedOut , .. } ) => {
323323 conn. desynchronized = false ;
324- return Err ( Error :: IoError ( e ) ) ;
324+ return None ;
325325 }
326- Err ( e) => return Err ( Error :: IoError ( e) ) ,
326+ Err ( e) => return Some ( Err ( Error :: IoError ( e) ) ) ,
327327 }
328328 }
329329 }
0 commit comments