From aa39e6c6a12a04270b45073d754496f932b0ed43 Mon Sep 17 00:00:00 2001 From: Fabrice Ongenae Date: Wed, 10 May 2017 16:33:16 +0200 Subject: [PATCH] call callback at the end of all required responses or if there is an error --- lib/engine_socketio.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/engine_socketio.js b/lib/engine_socketio.js index 9a6c974..2903133 100644 --- a/lib/engine_socketio.js +++ b/lib/engine_socketio.js @@ -197,11 +197,15 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) { if (!err) { markEndTime(ee, context, startedAt); } - // Stop listening on the response channel only if all messages were received - if (requiredResponsesCountsByChannel[channel] - 1 === index) { + // Stop listening on the response channel only if all messages were received or if there is an error + if (requiredResponsesCountsByChannel[channel] - 1 === index || err) { socketio.off(channel); } - return callback(err, context); + + // Call the callback function if all channel messages were received or if there is an error + if (requiredResponsesCount === currentResponsesCount || err) { + callback(err, context); + } }); }); });