Skip to content

Commit

Permalink
Use setImmediate to force “data” and “done” events to be streamed in …
Browse files Browse the repository at this point in the history
…order
  • Loading branch information
Baptiste Jamin committed Apr 19, 2024
1 parent 70573a8 commit 00d0ea0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/mirage.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,17 @@ Mirage.prototype.__doPostStream = function(
// Clear previous stall timeout (as needed)
fnCancelNextChunkStall();

// Raise 'done' event
emitter.emit("done");
setImmediate(function() {
// Raise 'done' event
emitter.emit("done");
});
} else {
// Raise 'data' event
emitter.emit("data", JSON.parse(dataPart));
let _jsonDataPart = _JSON.parse(dataPart);

setImmediate(function() {
// Raise 'data' event
emitter.emit("data", _jsonDataPart);
});
}
}
}
Expand Down

0 comments on commit 00d0ea0

Please sign in to comment.