From 5945162a8312d2a3d74ec17239db63934499bda1 Mon Sep 17 00:00:00 2001 From: Marvel Mathew Date: Tue, 19 Sep 2017 14:53:45 -0400 Subject: [PATCH] Fat arrow --- lib/index.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 83ec7e6..5414c77 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,7 +82,6 @@ class Subscriber extends events.EventEmitter { } topic.subscribe(subscriptionName, (err, subscription) => { - if (err) { console.error(`Failed to create subscription ${err}`); return; @@ -90,14 +89,16 @@ class Subscriber extends events.EventEmitter { console.log(`Subscription ${subscription.name} created.`); - function deleteSubscription() { + const deleteSubscription = () => { removeListeners(); - console.log('Subscriber: Signal received, deleting subscription'); - subscription.delete().then(() => { - console.log('Subscriber: subscription deleted...'); - }, (err) => { - console.error(`Subscriber: Error deleting subscription`, err); - }); + if (!this.disableFanOut) { + console.log('Subscriber: Signal received, deleting subscription'); + subscription.delete().then(() => { + console.log('Subscriber: subscription deleted...'); + }, (err) => { + console.error(`Subscriber: Error deleting subscription`, err); + }); + } } function messageHandler(message) { @@ -127,17 +128,13 @@ class Subscriber extends events.EventEmitter { subscription.removeListener('message', onMessage); subscription.removeListener('error', onError); - if (!this.disableFanOut) { - process.removeListener('SIGTERM', deleteSubscription); - process.removeListener('SIGINT', deleteSubscription); - } + process.removeListener('SIGTERM', deleteSubscription); + process.removeListener('SIGINT', deleteSubscription); } // Handle termination, delete the subscription (require graceful shutdowm) - if (!this.disableFanOut) { - process.on('SIGTERM', deleteSubscription); - process.on('SIGINT', deleteSubscription); - } + process.on('SIGTERM', deleteSubscription); + process.on('SIGINT', deleteSubscription); // Bind the subscription subscription.on('message', onMessage);