this.logger = logger;
this.db = db;
- this.options = Object.assign({}, defaultOptions, options);
+ this.options = {
+ ...defaultOptions,
+ ...options,
+ };
this.notificationEventName = 'notification';
this.connection = null;
delete this.reconnectPending;
}
if (this.connection) {
- this.connection.client.removeListener(this.notificationEventName, this.onNotificationBound);
+ this.connection.client.removeListener(this.notificationEventName, this._onNotificationBound);
this.connection.done();
this.connection = null;
await this.options.connectionLostCallback();
/**
* Notify callback.
- * @param {Object} data
+ * @param {object} data listener notification
*/
async _onNotification(data) {
const _scope = _fileScope('_onNotification');
/**
* Notify callback and attempt to reconnect.
- * @param {*} error
- * @param {*} event
+ * @param {*} error error
+ * @param {*} event event
*/
async _onConnectionLost(error, event) {
const _scope = _fileScope('_onConnectionLost');
this.logger.error(_scope, 'listener connection lost', { error, event });
this.connection = null;
try {
- event.client.removeListener(this.notificationEventName, this.onNotificationBound);
+ event.client.removeListener(this.notificationEventName, this._onNotificationBound);
} catch (e) {
this.logger.error(_scope, 'failed to remove listener', { error: e });
// That's okay, it was probably just gone anyhow.
/**
* Schedule an attempt to establish a connection.
- * @param {Number} delay
- * @param {Number} retriesRemaining
+ * @param {number} delay reconnect delay
+ * @param {number} retriesRemaining retry countdown
*/
async _reconnect(delay, retriesRemaining) {
const _scope = _fileScope('_reconnect');