Skip to content

Instantly share code, notes, and snippets.

@tpitale
Last active August 29, 2015 14:01
Show Gist options
  • Save tpitale/9db0b4e16fa7e888d162 to your computer and use it in GitHub Desktop.
Save tpitale/9db0b4e16fa7e888d162 to your computer and use it in GitHub Desktop.
Implementation of wait_for_notify with PG and Celluloid::IO
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