Wait for and return any notifications that return within timeout
Wait for and return any notifications that return within timeout
Once you subscribe to notifications with LISTEN, use this to wait for responses on each channel.
postgresWaitForNotify(conn, timeout =1)
Arguments
conn: a PqConnection object, produced by DBI::dbConnect()
timeout: How long to wait, in seconds. Default 1
Returns
If a notification was available, a list of:
channel: Name of channel
pid: PID of notifying server process
payload: Content of notification
If no notifications are available, return NULL
Examples
library(DBI)library(callr)# listen for messages on the grapevinedb_listen <- dbConnect(RPostgres::Postgres())dbExecute(db_listen,"LISTEN grapevine")# Start another process, which sends a message after a delayrp <- r_bg(function(){ library(DBI) Sys.sleep(0.3) db_notify <- dbConnect(RPostgres::Postgres()) dbExecute(db_notify,"NOTIFY grapevine, 'psst'") dbDisconnect(db_notify)})# Sleep until we get the messagen <-NULLwhile(is.null(n)){ n <- RPostgres::postgresWaitForNotify(db_listen,60)}stopifnot(n$payload =='psst')# Tidy uprp$wait()dbDisconnect(db_listen)