diff options
author | Alexander Borisov <alexander.borisov@nginx.com> | 2018-12-19 15:56:01 +0300 |
---|---|---|
committer | Alexander Borisov <alexander.borisov@nginx.com> | 2018-12-19 15:56:01 +0300 |
commit | f47a5db506911f1cf117bdc15474d40508bb7601 (patch) | |
tree | b82495f3cf8ff569a3f662432bc1b9238f851581 /src/nodejs/unit-http/http_server.js | |
parent | 13c9ebccca9c7bee80f4b9c1da4c128435d9dac1 (diff) | |
download | unit-f47a5db506911f1cf117bdc15474d40508bb7601.tar.gz unit-f47a5db506911f1cf117bdc15474d40508bb7601.tar.bz2 |
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.
Diffstat (limited to '')
-rwxr-xr-x | src/nodejs/unit-http/http_server.js | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 9b7b8403..8a536cde 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -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"); }); }; |