@@ -170,7 +170,7 @@ pub struct AsyncPgConnection {
170
170
transaction_state : Arc < Mutex < AnsiTransactionManager > > ,
171
171
metadata_cache : Arc < Mutex < PgMetadataCache > > ,
172
172
connection_future : Option < broadcast:: Receiver < Arc < tokio_postgres:: Error > > > ,
173
- notification_rx : Option < mpsc:: UnboundedReceiver < diesel:: pg:: PgNotification > > ,
173
+ notification_rx : Option < mpsc:: UnboundedReceiver < QueryResult < diesel:: pg:: PgNotification > > > ,
174
174
shutdown_channel : Option < oneshot:: Sender < ( ) > > ,
175
175
// a sync mutex is fine here as we only hold it for a really short time
176
176
instrumentation : Arc < std:: sync:: Mutex < DynInstrumentation > > ,
@@ -509,7 +509,7 @@ impl AsyncPgConnection {
509
509
async fn setup (
510
510
conn : tokio_postgres:: Client ,
511
511
connection_future : Option < broadcast:: Receiver < Arc < tokio_postgres:: Error > > > ,
512
- notification_rx : Option < mpsc:: UnboundedReceiver < diesel:: pg:: PgNotification > > ,
512
+ notification_rx : Option < mpsc:: UnboundedReceiver < QueryResult < diesel:: pg:: PgNotification > > > ,
513
513
shutdown_channel : Option < oneshot:: Sender < ( ) > > ,
514
514
instrumentation : Arc < std:: sync:: Mutex < DynInstrumentation > > ,
515
515
) -> ConnectionResult < Self > {
@@ -731,7 +731,7 @@ impl AsyncPgConnection {
731
731
732
732
pub fn notification_stream (
733
733
& mut self ,
734
- ) -> impl futures_core:: Stream < Item = diesel:: pg:: PgNotification > + ' _ {
734
+ ) -> impl futures_core:: Stream < Item = QueryResult < diesel:: pg:: PgNotification > > + ' _ {
735
735
match & mut self . notification_rx {
736
736
None => Either :: Left ( futures_util:: stream:: pending ( ) ) ,
737
737
Some ( rx) => Either :: Right ( futures_util:: stream:: unfold ( rx, async |rx| {
@@ -987,7 +987,7 @@ fn drive_connection<S>(
987
987
mut conn : tokio_postgres:: Connection < tokio_postgres:: Socket , S > ,
988
988
) -> (
989
989
broadcast:: Receiver < Arc < tokio_postgres:: Error > > ,
990
- mpsc:: UnboundedReceiver < diesel:: pg:: PgNotification > ,
990
+ mpsc:: UnboundedReceiver < QueryResult < diesel:: pg:: PgNotification > > ,
991
991
oneshot:: Sender < ( ) > ,
992
992
)
993
993
where
@@ -996,23 +996,25 @@ where
996
996
let ( error_tx, error_rx) = tokio:: sync:: broadcast:: channel ( 1 ) ;
997
997
let ( notification_tx, notification_rx) = tokio:: sync:: mpsc:: unbounded_channel ( ) ;
998
998
let ( shutdown_tx, mut shutdown_rx) = tokio:: sync:: oneshot:: channel ( ) ;
999
+ let mut conn = futures_util:: stream:: poll_fn ( move |cx| conn. poll_message ( cx) ) ;
999
1000
1000
1001
tokio:: spawn ( async move {
1001
- let mut conn = futures_util:: stream:: poll_fn ( |cx| conn. poll_message ( cx) ) ;
1002
-
1003
1002
loop {
1004
1003
match futures_util:: future:: select ( & mut shutdown_rx, conn. next ( ) ) . await {
1005
1004
Either :: Left ( _) | Either :: Right ( ( None , _) ) => break ,
1006
1005
Either :: Right ( ( Some ( Ok ( tokio_postgres:: AsyncMessage :: Notification ( notif) ) ) , _) ) => {
1007
- let _: Result < _ , _ > = notification_tx. send ( diesel:: pg:: PgNotification {
1006
+ let _: Result < _ , _ > = notification_tx. send ( Ok ( diesel:: pg:: PgNotification {
1008
1007
process_id : notif. process_id ( ) ,
1009
1008
channel : notif. channel ( ) . to_owned ( ) ,
1010
1009
payload : notif. payload ( ) . to_owned ( ) ,
1011
- } ) ;
1010
+ } ) ) ;
1012
1011
}
1013
1012
Either :: Right ( ( Some ( Ok ( _) ) , _) ) => { }
1014
1013
Either :: Right ( ( Some ( Err ( e) ) , _) ) => {
1015
- let _ = error_tx. send ( Arc :: new ( e) ) ;
1014
+ let e = Arc :: new ( e) ;
1015
+ let _: Result < _ , _ > = error_tx. send ( e. clone ( ) ) ;
1016
+ let _: Result < _ , _ > =
1017
+ notification_tx. send ( Err ( error_helper:: from_tokio_postgres_error ( e) ) ) ;
1016
1018
break ;
1017
1019
}
1018
1020
}
0 commit comments