Pike v8.0 release 1738

Method Sql.postgres()->set_notify_callback()


Method set_notify_callback

void set_notify_callback()
void set_notify_callback(function(:void) f)
void set_notify_callback(function(:void) f, int|float poll_delay)

Description

With Postgres you can associate events and notifications to tables. This function allows you to detect and handle such events.

With no arguments, resets and removes any callback you might have put previously, and any polling cycle.

With one argument, sets the notification callback (there can be only one for each sqlobject).

With two arguments, sets a notification callback and sets a polling cycle.

The polling cycle is necessary because of the way notifications are delivered, that is piggyback with a query result. This means that if you don't do any query, you'll receive no notification. The polling cycle starts a call_out cycle which will do an empty query when the specified interval expires, so that pending notifications may be delivered.

The callback function must return no value, and takes a string argument, which will be the name of the table on which the notification event has occurred. In future versions, support for user-specified arguments will be added.

Note

The polling cycle can be run only if your process is in "event-driven mode" (that is, if 'main' has returned a negative number).

This function is Postgres-specific, and thus it is not available through the generic SQL-interface.

FIXME

An integer can be passed as first argument, but it's effect is not documented.