Class: PgSubscriber

reactive-pg-client-js/pg_subscriber~ PgSubscriber

new PgSubscriber()

Source:

Methods

actualConnection() → {PgConnection}

Source:
Returns:
the actual connection to Postgres, it might be null
Type
PgConnection

channel(name) → {PgChannel}

Return a channel for the given name.
Parameters:
Name Type Description
name string the channel name

This will be the name of the channel exactly as held by Postgres for sending notifications. Internally this name will be truncated to the Postgres identifier maxiumum length of (NAMEDATALEN = 64) - 1 == 63 characters, and prepared as a quoted identifier without unicode escape sequence support for use in LISTEN/UNLISTEN commands. Examples of channel names and corresponding NOTIFY commands:

  • when name == "the_channel": NOTIFY the_channel, 'msg', NOTIFY The_Channel, 'msg', or NOTIFY "the_channel", 'msg' succeed in delivering a message to the created channel
  • when name == "The_Channel": NOTIFY "The_Channel", 'msg', succeeds in delivering a message to the created channel
Source:
Returns:
the channel
Type
PgChannel

close()

Close the subscriber, the retry policy will not be invoked.
Source:

closed() → {boolean}

Source:
Returns:
whether the subscriber is closed
Type
boolean

closeHandler(handler) → {PgSubscriber}

Set an handler called when the subscriber is closed.
Parameters:
Name Type Description
handler function the handler
Source:
Returns:
a reference to this, so the API can be used fluently
Type
PgSubscriber

connect(handler) → {PgSubscriber}

Connect the subscriber to Postgres.
Parameters:
Name Type Description
handler function the handler notified of the connection success or failure
Source:
Returns:
a reference to this, so the API can be used fluently
Type
PgSubscriber

reconnectPolicy(policy) → {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:
Name Type Description
policy function the policy to set
Source:
Returns:
a reference to this, so the API can be used fluently
Type
PgSubscriber