Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PgSubscriber

A class for managing subscriptions using LISTEN/UNLISTEN to Postgres channels.

The subscriber manages a single connection to Postgres.

Hierarchy

  • PgSubscriber

Index

Methods

actualConnection

  • Returns PgConnection

channel

  • Return a channel for the given name.

    Parameters

    • name: string

    Returns PgChannel

close

  • close(): PromiseLike<void>
  • close(handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): void
  • Close the subscriber, the retry policy will not be invoked.

    Returns PromiseLike<void>

  • Close the subscriber, the retry policy will not be invoked.

    Parameters

    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns void

closeHandler

  • closeHandler(handler: ((res: void) => void) | Handler<void>): PgSubscriber
  • Set an handler called when the subscriber is closed.

    Parameters

    • handler: ((res: void) => void) | Handler<void>

    Returns PgSubscriber

closed

  • closed(): boolean
  • Returns boolean

connect

  • connect(): PromiseLike<void>
  • connect(handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>): PgSubscriber
  • Connect the subscriber to Postgres.

    Returns PromiseLike<void>

  • Connect the subscriber to Postgres.

    Parameters

    • handler: ((res: AsyncResult<void>) => void) | Handler<AsyncResult<void>>

    Returns PgSubscriber

reconnectPolicy

  • reconnectPolicy(policy: (arg: number) => number): PgSubscriber
  • Set the reconnect policy that is executed when the subscriber is disconnected.

    When the subscriber is disconnected, the policy function is called with the actual number of retries and returns an amountOfTime value:

    • when amountOfTime < 0: the subscriber is closed and there is no retry
    • when amountOfTime == 0: the subscriber retries to connect immediately
    • when amountOfTime > 0: the subscriber retries after amountOfTime milliseconds

    The default policy does not perform any retries.

    Parameters

    • policy: (arg: number) => number
        • (arg: number): number
        • Parameters

          • arg: number

          Returns number

    Returns PgSubscriber

Static subscriber

  • Create a subscriber.

    Parameters

    Returns PgSubscriber

Generated using TypeDoc