File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -341,15 +341,19 @@ function Postgres(a, b) {
341341
342342 if ( channel in listeners ) {
343343 listeners [ channel ] . push ( fn )
344- return Promise . resolve ( Object . assign ( { } , listener . result , { unlisten } ) )
344+ return Promise . resolve ( Object . create ( listener . result , {
345+ unlisten : { value : unlisten }
346+ } ) )
345347 }
346348
347349 listeners [ channel ] = [ fn ]
348350
349351 return query ( { raw : true } , listener . conn , 'listen ' + escape ( channel ) )
350352 . then ( ( result ) => {
351- listener . result = result
352- return Object . assign ( { } , listener . result , { unlisten } )
353+ Object . assign ( listener . result , result )
354+ return Object . create ( listener . result , {
355+ unlisten : { value : unlisten }
356+ } )
353357 } )
354358
355359 function unlisten ( ) {
@@ -382,8 +386,8 @@ function Postgres(a, b) {
382386 } ,
383387 options
384388 ) )
385- listener = { conn, result : null }
386- all . push ( conn )
389+ listener = { conn, result : { } } ;
390+ all . push ( conn ) ;
387391 return listener
388392 }
389393
Original file line number Diff line number Diff line change @@ -593,6 +593,20 @@ t('listen reconnects', async() => {
593593 return [ 'ab' , xs . join ( '' ) ]
594594} )
595595
596+ t ( 'listen result reports correct connection state after reconnection' , async ( ) => {
597+ const listener = postgres ( options )
598+ , xs = [ ]
599+
600+ const result = await listener . listen ( 'test' , x => xs . push ( x ) )
601+ const initialPid = result . state . pid
602+ await sql . notify ( 'test' , 'a' )
603+ await sql `select pg_terminate_backend(${ initialPid } ::int)`
604+ await delay ( 50 )
605+ listener . end ( )
606+
607+ return [ result . state . pid !== initialPid , true ]
608+ } )
609+
596610t ( 'unlisten removes subscription' , async ( ) => {
597611 const listener = postgres ( options )
598612 , xs = [ ]
You can’t perform that action at this time.
0 commit comments