mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

listen & unlisten are blocking ops, so handle incoming notifications #81

Closed akarelas closed 2 years ago

akarelas commented 2 years ago

Summary

This PR adds a $pubsub->db->_notifications call at the end of $pubsub->db->listen and $pubsub->db->unlisten, which should exist there as these two methods issue blocking SQL operations.

Motivation

Without these changes, a $pubsub->listen on a new channel that directly follows a $pg->db->notify on one we're already listening on, would cause that notification to not be received in a timely manner (but potentially a lot later). I wanted to fix this.

References

This PR fixes issue #77.

akarelas commented 2 years ago

The current tests are the best tests I can write for this PR. Apologies, and please advise how to improve if they are not enough.

akarelas commented 2 years ago

I wonder if I should have left the timers in the tests.

akarelas commented 2 years ago

Should I have left the timers in the test? I can revert back to that, if you want.

kraih commented 2 years ago

If you want someone to review your work in progress PR you have to make sure you make it clear that it is now ready for review.