pg-listener API
    Preparing search index...

    Class PgListener

    Provides functionality to listen to Postgres NOTIFY / LISTEN events and handle them dynamically using provided configuration and event handlers.

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    Configuration object for initializing the instance.

    connections: IListenConnection[] = []

    A list of all live connections, created by method listen.

    Connections that are no longer live are automatically removed from the list.

    This is mainly for the logging purpose / diagnostics.

    Beware of calling IListenResult.cancel while iterating over it, because IListenResult.cancel removes the connection from this list. In most cases, cancelAll is a better choice.

    Methods

    • Initiates listening to specified channels for notifications, while automatically handling reconnection on lost connections.

      It allocates and fully occupies one physical connection from the pool, allowing for the flexibility of choosing how to split channels across connections.

      Once connected initially, the result is automatically registered within connections.

      If you want a connection just for sending notifications, pass in an empty list of channels.

      Parameters

      • channels: string[]

        An array of channel names to listen to. It can be empty if you want a connection just for sending notifications.

      • Optionale: IListenEvents

        Optional event handlers for managing notifications, connection events, and errors.

      Returns Promise<IListenResult>

      A promise that resolves to an object with post-connect API.