Node.js: napi_call_function() replaced with napi_make_callback().

The sequence of napi_open_callback_scope(),
napi_call_function(), and napi_close_callback_scope() functions calls
executes the provided JS code and all functions enqueued by
process.nextTick() and Promises during this execution.
This commit is contained in:
Alexander Borisov
2018-12-19 15:56:01 +03:00
parent 13c9ebccca
commit f47a5db506
2 changed files with 63 additions and 27 deletions

View File

@@ -342,7 +342,7 @@ Server.prototype.listen = function () {
this.unit.listen();
};
Server.prototype.run_events = function (server, req, res) {
Server.prototype.emit_events = function (server, req, res) {
req.server = server;
res.server = server;
req.res = res;
@@ -350,18 +350,11 @@ Server.prototype.run_events = function (server, req, res) {
server.buffer = server.unit._read(req.socket.req_pointer);
/* Important!!! setImmediate starts the next iteration in Node.js loop. */
setImmediate(function () {
server.emit("request", req, res);
server.emit("request", req, res);
Promise.resolve().then(() => {
req.emit("finish");
req.emit("end");
if (res.finished) {
unit_lib.unit_response_end(res);
}
});
process.nextTick(() => {
req.emit("finish");
req.emit("end");
});
};