From 1418b7a801ee19d8b45201c844c86366f988c5d4 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Fri, 14 Oct 2016 17:36:04 +0800 Subject: [PATCH] Fix socket disconnect might interrupt loop issue --- lib/realtime.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/realtime.js b/lib/realtime.js index d069a48..b50e05b 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -97,7 +97,9 @@ var updater = setInterval(function () { for (var i = 0, l = note.socks.length; i < l; i++) { var sock = note.socks[i]; if (typeof sock !== 'undefined' && sock) { - sock.disconnect(true); + setTimeout(function () { + sock.disconnect(true); + }, 0); } } return callback(err, null); @@ -787,7 +789,9 @@ function connection(socket) { sock.emit('info', { code: 403 }); - return sock.disconnect(true); + setTimeout(function () { + sock.disconnect(true); + }, 0); } } } @@ -818,7 +822,9 @@ function connection(socket) { var sock = note.socks[i]; if (typeof sock !== 'undefined' && sock) { sock.emit('delete'); - return sock.disconnect(true); + setTimeout(function () { + sock.disconnect(true); + }, 0); } } }).catch(function (err) {