-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override Response.setTimeout to make response timeout handler work #69
Override Response.setTimeout to make response timeout handler work #69
Conversation
lib/response.js
Outdated
@@ -46,7 +46,18 @@ function Response (req, onEnd, reject) { | |||
|
|||
util.inherits(Response, http.ServerResponse) | |||
|
|||
let timeoutHandle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reference should be stored in the constructor function Response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eomm Id don't really get it. do you mean I should set it as a property and access it as this.timeoutHandle
?
lib/response.js
Outdated
@@ -46,7 +46,18 @@ function Response (req, onEnd, reject) { | |||
|
|||
util.inherits(Response, http.ServerResponse) | |||
|
|||
let timeoutHandle | |||
Response.prototype.setTimeout = function (msecs, callback) { | |||
if (callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not permit to call this function without a callback, otherwise, the user can't understand why it is not working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, shall I throw an error if no callback is specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the http docs, the callback is optional: https://nodejs.org/api/http.html#http_response_settimeout_msecs_callback
lib/response.js
Outdated
Response.prototype.writeHead = function () { | ||
if (timeoutHandle) { | ||
clearTimeout(timeoutHandle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be the write
function a better place where clear this timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eomm ok, I'll move it there
lib/response.js
Outdated
let timeoutHandle | ||
Response.prototype.setTimeout = function (msecs, callback) { | ||
if (callback) { | ||
timeoutHandle = setTimeout(callback, msecs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to emit the 'timeout'
event when the setTimeout triggers (independently of the presence of the callback)
See https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina according to the docs, the timeout event should be emitted by the socket. how can I cet a reference to the underlying socket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is calling this.socket.emit('timeout')
enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Somebody please, merge this PR. |
Checklist
npm run test
andnpm run benchmark