Comparing version 3.0.0 to 3.1.0
30
index.js
@@ -8,10 +8,13 @@ 'use strict'; | ||
var delays = isNaN(time) ? time : {socket: time, connect: time}; | ||
var host = req._headers ? (' to ' + req._headers.host) : ''; | ||
req.timeoutTimer = setTimeout(function timeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Connection timed out on request' + host); | ||
e.code = 'ETIMEDOUT'; | ||
req.emit('error', e); | ||
}, time); | ||
if (delays.connect !== undefined) { | ||
req.timeoutTimer = setTimeout(function timeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Connection timed out on request' + host); | ||
e.code = 'ETIMEDOUT'; | ||
req.emit('error', e); | ||
}, delays.connect); | ||
} | ||
@@ -24,8 +27,11 @@ // Clear the connection timeout timer once a socket is assigned to the | ||
clear(); | ||
socket.setTimeout(time, function socketTimeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Socket timed out on request' + host); | ||
e.code = 'ESOCKETTIMEDOUT'; | ||
req.emit('error', e); | ||
}); | ||
if (delays.socket !== undefined) { | ||
socket.setTimeout(delays.socket, function socketTimeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Socket timed out on request' + host); | ||
e.code = 'ESOCKETTIMEDOUT'; | ||
req.emit('error', e); | ||
}); | ||
} | ||
}); | ||
@@ -32,0 +38,0 @@ }); |
{ | ||
"name": "timed-out", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Emit `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -31,8 +31,13 @@ # timed-out [![Build Status](https://travis-ci.org/floatdrop/timed-out.svg?branch=master)](https://travis-ci.org/floatdrop/timed-out) | ||
*Required* | ||
Type: `number` | ||
Type: `number` or `object` | ||
Time in milliseconds to wait for `connect` event on socket and also time to wait on inactive socket. | ||
Or you can pass Object with following fields: | ||
- `connnect` - time to wait for connection | ||
- `socket` - time to wait for activity on socket | ||
## License | ||
MIT © [Vsevolod Strukchinsky](floatdrop@gmail.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3914
39
43