Closed Globik closed 7 years ago
pool.on('notification', callback)
doesn't work for you?
I don't know. But I'll try. I'm using node-pg-pool version 1.6.0 and node-pg-subpub
Try getting the client
from the pool
, it works for me. Here's an ES6 example.
const client = await pool.connect()
client.on('notification', msg => {
console.log(msg)
})
client.query('LISTEN channel')
I would recommend strongly against using a pooled client for listen/notify
. For the listener instantiate a stand-alone client and connect it. The pool will close clients which haven't been checked out after a configurable interval - including any clients which you have have called listen
on.
I have it on my roadmap to document proper usage of listen/notify
- for now just don't use the pool for that client:
const listener = new pg.Client()
listener.connect()
listener.query('LISTEN channel')
listener.on('notification', msg => {
// do your thing here
})
No event works with perform pg_notify.