From d7fbf3c39e9de6e56a786d1b2119c3bd899f316b Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Sun, 10 Jul 2016 20:22:35 -0700 Subject: [PATCH] fix processing waiting callbacks inside next_socket --- proxy.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/proxy.js b/proxy.js index 1000930..75d5e3e 100644 --- a/proxy.js +++ b/proxy.js @@ -128,7 +128,11 @@ Proxy.prototype._handle_socket = function(socket) { }); self.sockets.push(socket); + self._process_waiting(); +}; +Proxy.prototype._process_waiting = function() { + const self = this; const wait_cb = self.waiting.shift(); if (wait_cb) { self.debug('handling queued request'); @@ -176,12 +180,7 @@ Proxy.prototype.next_socket = function(handler) { return; } - const wait = self.waiting.shift(); - self.debug('processing queued cb'); - if (wait) { - self.next_socket(cb); - return; - } + self._process_waiting(); }); };