Comparing version 2.1.0 to 2.2.0
@@ -8,6 +8,8 @@ 'use strict' | ||
class Ping { | ||
constructor () { | ||
constructor (options) { | ||
this.startTime = null | ||
this.endTime = null | ||
this.req = new Req() | ||
this.options = options | ||
this.req = new Req(this.options) | ||
} | ||
@@ -31,2 +33,6 @@ | ||
destroy (cb) { | ||
this.req.abort(cb) | ||
} | ||
end () { | ||
@@ -33,0 +39,0 @@ this.endTime = Date.now() |
@@ -10,2 +10,3 @@ 'use strict' | ||
super() | ||
this.options = Object.assign({}, options) | ||
this.http = http | ||
@@ -87,2 +88,15 @@ this._req = null | ||
if (this.options.timeout || opts.timeout) { | ||
this._req.setTimeout(this.options.timeout || this.options.timeout, () => { | ||
if (this.hasReturned) { | ||
return | ||
} | ||
this.hasReturned = true | ||
const err = new Error('has timed out.') | ||
err.name = 'TimeoutError' | ||
return cb(err) | ||
}) | ||
} | ||
this._req.on('error', (err) => { | ||
@@ -89,0 +103,0 @@ if (this.hasReturned) { |
{ | ||
"name": "probe", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Ping and probe stuff.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,1 +20,18 @@ 'use strict' | ||
}) | ||
test('Throws a timeout', (t) => { | ||
t.plan(4) | ||
const config = { | ||
host: 'something.local', | ||
path:'/' | ||
} | ||
const req = new HTTPRequest({timeout: 50}) | ||
req.start(config, (err, res) => { | ||
t.ok(err) | ||
t.equals(err.name, 'TimeoutError') | ||
t.notOk(res) | ||
t.pass() | ||
t.end() | ||
}) | ||
}) |
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
14153
527