Skip to content

Commit 12b7207

Browse files
committed
perf: remove argument reassignment
1 parent 3ddb6bd commit 12b7207

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ unreleased
22
==========
33

44
* perf: enable strict mode
5+
* perf: remove argument reassignment
56

67
1.6.2 / 2015-05-11
78
==================

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ var onHeaders = require('on-headers');
2828
*/
2929

3030
module.exports = function timeout(time, options) {
31-
options = options || {};
31+
var opts = options || {};
3232

33-
time = typeof time === 'string'
33+
var delay = typeof time === 'string'
3434
? ms(time)
3535
: Number(time || 5000);
3636

37-
var respond = !('respond' in options) || options.respond === true;
37+
var respond = !('respond' in opts) || opts.respond === true;
3838

3939
return function(req, res, next) {
4040
var destroy = req.socket.destroy;
4141
var id = setTimeout(function(){
4242
req.timedout = true;
43-
req.emit('timeout', time);
44-
}, time);
43+
req.emit('timeout', delay);
44+
}, delay);
4545

4646
if (respond) {
47-
req.on('timeout', onTimeout(time, next));
47+
req.on('timeout', onTimeout(delay, next));
4848
}
4949

5050
req.clearTimeout = function(){
@@ -66,11 +66,11 @@ module.exports = function timeout(time, options) {
6666
};
6767
};
6868

69-
function onTimeout(time, cb){
69+
function onTimeout(delay, cb) {
7070
return function(){
7171
cb(createError(503, 'Response timeout', {
7272
code: 'ETIMEDOUT',
73-
timeout: time
73+
timeout: delay
7474
}));
7575
};
7676
}

0 commit comments

Comments
 (0)