Last active
August 29, 2015 14:01
-
-
Save tpitale/9db0b4e16fa7e888d162 to your computer and use it in GitHub Desktop.
Implementation of wait_for_notify with PG and Celluloid::IO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wait_for_notify(&block) | |
io = pg_connection.socket_io | |
while @listening do | |
Celluloid::IO.wait_readable(io) # blocks execution, but unblocks this actor | |
pg_connection.consume_input # fetch any input on this connection | |
# read the NOTIFY messages off the socket | |
while notification = pg_connection.notifies do | |
block.call( | |
notification[:relname], # channel | |
notification[:be_pid], # pid | |
notification[:extra] # payload | |
) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment