@@ -78,6 +78,7 @@ use message::BackendMessage::*;
78
78
use message:: FrontendMessage :: * ;
79
79
use message:: { FrontendMessage , BackendMessage , RowDescriptionEntry } ;
80
80
use message:: { WriteMessage , ReadMessage } ;
81
+ use notification:: { Notifications , Notification } ;
81
82
use rows:: { Rows , LazyRows } ;
82
83
use stmt:: { Statement , Column } ;
83
84
use types:: { IsNull , Kind , Type , SessionInfo , Oid , Other } ;
@@ -97,6 +98,7 @@ pub mod io;
97
98
pub mod rows;
98
99
pub mod stmt;
99
100
pub mod types;
101
+ pub mod notification;
100
102
101
103
const TYPEINFO_QUERY : & ' static str = "t" ;
102
104
@@ -231,68 +233,6 @@ impl HandleNotice for LoggingNoticeHandler {
231
233
}
232
234
}
233
235
234
- /// An asynchronous notification.
235
- #[ derive( Clone , Debug ) ]
236
- pub struct Notification {
237
- /// The process ID of the notifying backend process.
238
- pub pid : u32 ,
239
- /// The name of the channel that the notify has been raised on.
240
- pub channel : String ,
241
- /// The "payload" string passed from the notifying process.
242
- pub payload : String ,
243
- }
244
-
245
- /// An iterator over asynchronous notifications.
246
- pub struct Notifications < ' conn > {
247
- conn : & ' conn Connection
248
- }
249
-
250
- impl < ' a > fmt:: Debug for Notifications < ' a > {
251
- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
252
- DebugStruct :: new ( fmt, "Notifications" )
253
- . field ( "pending" , & self . conn . conn . borrow ( ) . notifications . len ( ) )
254
- . finish ( )
255
- }
256
- }
257
-
258
- impl < ' conn > Iterator for Notifications < ' conn > {
259
- type Item = Notification ;
260
-
261
- /// Returns the oldest pending notification or `None` if there are none.
262
- ///
263
- /// ## Note
264
- ///
265
- /// `next` may return `Some` notification after returning `None` if a new
266
- /// notification was received.
267
- fn next ( & mut self ) -> Option < Notification > {
268
- self . conn . conn . borrow_mut ( ) . notifications . pop_front ( )
269
- }
270
- }
271
-
272
- impl < ' conn > Notifications < ' conn > {
273
- /// Returns the oldest pending notification.
274
- ///
275
- /// If no notifications are pending, blocks until one arrives.
276
- pub fn next_block ( & mut self ) -> Result < Notification > {
277
- if let Some ( notification) = self . next ( ) {
278
- return Ok ( notification) ;
279
- }
280
-
281
- let mut conn = self . conn . conn . borrow_mut ( ) ;
282
- check_desync ! ( conn) ;
283
- match try!( conn. read_message_with_notification ( ) ) {
284
- NotificationResponse { pid, channel, payload } => {
285
- Ok ( Notification {
286
- pid : pid,
287
- channel : channel,
288
- payload : payload
289
- } )
290
- }
291
- _ => unreachable ! ( )
292
- }
293
- }
294
- }
295
-
296
236
/// Contains information necessary to cancel queries for a session.
297
237
#[ derive( Copy , Clone , Debug ) ]
298
238
pub struct CancelData {
@@ -947,7 +887,7 @@ impl Connection {
947
887
///
948
888
/// Use the `LISTEN` command to register this connection for notifications.
949
889
pub fn notifications < ' a > ( & ' a self ) -> Notifications < ' a > {
950
- Notifications { conn : self }
890
+ Notifications :: new ( self )
951
891
}
952
892
953
893
/// Creates a new prepared statement.
@@ -1444,3 +1384,7 @@ trait StatementInternals<'conn> {
1444
1384
trait ColumnNew {
1445
1385
fn new ( name : String , type_ : Type ) -> Column ;
1446
1386
}
1387
+
1388
+ trait NotificationsNew < ' conn > {
1389
+ fn new ( conn : & ' conn Connection ) -> Notifications < ' conn > ;
1390
+ }
0 commit comments