postgleam/notifications

LISTEN/NOTIFY on a low-level ConnectionState.

For most applications postgleam/listener is easier: it runs a dedicated connection and sends each notification to a Subject.

Types

A notification received from PostgreSQL.

pub type Notification =
  connection.Notification

Values

pub fn listen(
  state: connection.ConnectionState,
  channel: String,
  timeout: Int,
) -> Result(connection.ConnectionState, error.Error)

Listen on a channel.

pub fn notify(
  state: connection.ConnectionState,
  channel: String,
  payload: String,
  timeout: Int,
) -> Result(connection.ConnectionState, error.Error)

Send a notification on a channel (parameterised pg_notify).

pub fn receive_notifications(
  state: connection.ConnectionState,
  timeout: Int,
) -> Result(
  #(List(connection.Notification), connection.ConnectionState),
  error.Error,
)

Return the notifications received so far, oldest first. If there are none, wait up to timeout milliseconds for one to arrive. Returns an empty list when nothing arrives in time.

pub fn unlisten(
  state: connection.ConnectionState,
  channel: String,
  timeout: Int,
) -> Result(connection.ConnectionState, error.Error)

Stop listening on a channel.

✨ Search Document