Skip to content

Commit

Permalink
Fix borked emits
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed May 17, 2024
1 parent ab37ded commit 692ca5e
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions lib/mirage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down

0 comments on commit 692ca5e

Please sign in to comment.