Skip to content

Commit

Permalink
wsServer: cleaned up setInterval on closeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
d4tocchini committed Mar 29, 2020
1 parent c5171d2 commit cc1a446
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/wsServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ class wsServer {
const self = this;
self.config = config;
self.recorder = recorder;
self.checkBroadcastFlagTimer = null;
}

start() {
const self = this;
const config = self.config;
const recorder = self.recorder;
const recorder = self.recorder

return new Promise((resolve, reject) => {
//web socket interface
const wss = new WebSocketServer({
Expand All @@ -78,7 +80,7 @@ class wsServer {
// the flat to indicate wheter to broadcast the record
let broadcastFlag = true;

setInterval(() => {
self.checkBroadcastFlagTimer = setInterval(() => {
broadcastFlag = true;
sendMultipleMessage();
}, 50);
Expand Down Expand Up @@ -161,6 +163,9 @@ class wsServer {

closeAll() {
const self = this;
if (self.checkBroadcastFlagTimer) {
clearInterval(self.checkBroadcastFlagTimer);
}
return new Promise((resolve, reject) => {
self.wss.close((e) => {
if (e) {
Expand Down

0 comments on commit cc1a446

Please sign in to comment.