summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http/http_server.js
diff options
context:
space:
mode:
authorAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:56:13 +0300
committerAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:56:13 +0300
commit607653c0f12a99981dbf3118b60b84ded4084d50 (patch)
treea45c3e5832b034917ccbe9c2c7026dc9ca21537a /src/nodejs/unit-http/http_server.js
parent704fe556b423795d06f79cec3a3406ef6defb635 (diff)
downloadunit-607653c0f12a99981dbf3118b60b84ded4084d50.tar.gz
unit-607653c0f12a99981dbf3118b60b84ded4084d50.tar.bz2
Node.js: calling write callback asynchronously.
Diffstat (limited to 'src/nodejs/unit-http/http_server.js')
-rwxr-xr-xsrc/nodejs/unit-http/http_server.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index c93d2b10..28f2303f 100755
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -217,7 +217,19 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
}
if (typeof callback === 'function') {
- callback(this);
+ /*
+ * The callback must be called only when response.write() caller
+ * completes. process.nextTick() postpones the callback execution.
+ *
+ * process.nextTick() is not technically part of the event loop.
+ * Instead, the nextTickQueue will be processed after the current
+ * operation completes, regardless of the current phase of
+ * the event loop. All callbacks passed to process.nextTick()
+ * will be resolved before the event loop continues.
+ */
+ process.nextTick(function () {
+ callback(this);
+ }.bind(this));
}
};