method PostgresConnector.listen
PostgresConnector.listen(channel: string): Task<Channel<Notification, ListenFailed>, ListenFailed>

Subscribe to a PostgreSQL NOTIFY channel.

Resolves once the dedicated connection is established and LISTEN is issued. The channel streams notifications until closed or the connection drops. Each active subscription holds a dedicated pg.Client connection.

Cleanup (UNLISTEN + disconnect) runs when the consumer stops iterating, for example after take(), takeWhile(), or exhausting the stream. Calling ch.close() without consuming does not trigger cleanup. The dedicated pg.Client stays connected until the channel is iterated and the generator finalizes.

Examples

Example 1

const ch = await connector.listen('orders').run()
for await (const n of ch.successes()) {
  console.log(n.payload)
}

Parameters

channel: string

Return Type

Task<Channel<Notification, ListenFailed>, ListenFailed>

Usage

import { type PostgresConnector } from ".";