Replies: 14 comments 11 replies
-
Beta Was this translation helpful? Give feedback.
-
|
These all remain unresolved issues. I tried once before, with pg-listener, but never finished it, it's not working, though it might be worth resuming work on it. I used my own code from the example I provided, and it worked well on Windows/Linux/Mac, but I never tested it in AWS, which has its own connection-related corks. Maybe check out this post, which looks good, though I never tested it. I might refactor my example based on that. |
Beta Was this translation helpful? Give feedback.
-
|
A basic listener in TypeScript would look like this: async function listen(channel: string, cb: (data: string) => void): Promise<null> {
const sco = await db.connect({direct: true, onLost: () => listen(channel, cb)});
sco.client.on('notification', ({payload}) => cb(payload));
return sco.none('LISTEN $1~', channel);
}...which I appended to the Robust Listeners. But then you can improve on it, by adding support for multiple channels on the same connection, allow un-listening, closing unused event notification handlers, etc. Usage: listen('my_channel', (data) => {
console.log(data);
}).catch((e: any) => {
console. Error('DB Connection Issue:', e.message);
}); |
Beta Was this translation helpful? Give feedback.
-
|
You now can find way more in the update for robust listeners 😉 |
Beta Was this translation helpful? Give feedback.
-
|
Based on everything I implemented today I decided the volume of code and its importance warrant placing it all into its own library. Therefore, I have started reviving the old unfinished pg-listener, rewriting from scratch, based on the complete solution. From now on, please follow that repo. Once it is ready, it will replace all the old references to notification listening. |
Beta Was this translation helpful? Give feedback.
-
|
UPDATE-1 Initial draft has been published as v0.0.2. UPDATE-2 After v0.0.3, successfully tested the library locally, it works as expected. Now focus is on tests + documentation. UPDATE-3 The library has reached v0.0.5, it is solid, according to my local tests, though unit tests are non-existent so far. At least documentation is enough to get started. It is no longer a draft; it is quite decent now. I am parking it here for now, having spent all day on it today, because I myself will likely be needing it also. Plus, many people were asking about it in the past. I will get back to it when I have time again. |
Beta Was this translation helpful? Give feedback.
-
|
Once pg-listener reached v0.0.9, I replaced everything inside Robust Listeners with it. This is the only way forward now. |
Beta Was this translation helpful? Give feedback.
-
|
Maybe you guys can help me with this little issue? 😉 |
Beta Was this translation helpful? Give feedback.
-
|
You guys have gone awfully quiet here, while I continued working on this 🤭 We now have very solid release, with almost 100% test coverage (plus GitHub CI integration), and I even have put together a separate solution for RxJs, in the examples 😉 |
Beta Was this translation helpful? Give feedback.
-
|
@slidenerd Will you be able to provide feedback on pg-listener? It's been a while :) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
🙏🙏🙏 pg-listener is the definitive answer thanks to vitaly-t's fantastic efforts in 2025 people. I am closing this issue. |
Beta Was this translation helpful? Give feedback.
-
|
I had so much fun with the RxJs extension for this library, that I decided to have a go at an alternative pure-RxJs solution that can work for both |
Beta Was this translation helpful? Give feedback.
-
|
pg-listener has been significantly improved since, for even easier use. For example, the addition of createIterable allows for the following approach to handling messages: const result = await ls.listen(['channel_1', 'channel_2']);
for await (const msg of result.createIterable()) {
console.log(msg);
} |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions