Skip to content

Commit

Permalink
added more debug logging and fixed unsubscribe bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jackHedaya committed Apr 3, 2019
1 parent 8643afc commit adf9855
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RealtimeStock extends EventEmitter {
*/
async subscribe(stock) {
this.subscriptions.push(stock);
this.emit("debug", `Subscribing to ${stock.toUpperCase()}.`);

await this._run(stock);
}
Expand All @@ -62,7 +63,10 @@ class RealtimeStock extends EventEmitter {
async unsubscribe(stock) {
const pageIndex = this.subscriptions.indexOf(stock);

if (pageIndex === -1) {
if (pageIndex !== -1) {
this.subscriptions.splice(pageIndex, 1);
this.emit("debug", `Unsubscribed from ${stock.toUpperCase()}.`);
} else {
this.emit("debug", `${stock.toUpperCase()} is not a subscription.`);
return;
}
Expand Down

0 comments on commit adf9855

Please sign in to comment.