From 692ca5e9d5d54d91e69b251bd9ee97aa5c8ed4d3 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 17 May 2024 15:56:07 +0200 Subject: [PATCH] Fix borked emits --- lib/mirage.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/mirage.js b/lib/mirage.js index add3dc9..62c3758 100644 --- a/lib/mirage.js +++ b/lib/mirage.js @@ -277,22 +277,14 @@ Mirage.prototype.__doPostStream = function( // special non-user level events. if (eventBlock === "system") { if (dataPart === STREAM_START_TAG) { - // Process at next event loop tick, as the 'start' event \ - // might come out-of-order. - setImmediate(function() { - // Raise 'start' event - emitter.emit("start"); - }); + // Raise 'start' event + emitter.emit("start"); } else if (dataPart === STREAM_DONE_TAG) { // Clear previous stall timeout (as needed) fnCancelNextChunkStall(); - // Process at next event loop tick, as the 'done' event \ - // might come out-of-order. - setImmediate(function() { - // Raise 'done' event - emitter.emit("done"); - }); + // Raise 'done' event + emitter.emit("done"); } } else { var dataPartObject = JSON.parse(dataPart); @@ -306,12 +298,8 @@ Mirage.prototype.__doPostStream = function( eventName = (":" + eventName); } - // Process at next event loop tick, as the 'data' event might \ - // come out-of-order. - setImmediate(function() { - // Raise event (fallback to 'data' if no event block) - emitter.emit(eventName, dataPartObject); - }); + // Raise event (fallback to 'data' if no event block) + emitter.emit(eventName, dataPartObject); } // Abort parsing of line there.