@dashevo/dashd-rpc
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -13,2 +13,3 @@ /* eslint-disable */ | ||
this.pass = opts.pass || 'pass'; | ||
this.timeout = opts.timeout; | ||
this.protocol = opts.protocol === 'http' ? http : https; | ||
@@ -78,2 +79,6 @@ this.batchedCalls = null; | ||
agent: self.disableAgent ? false : undefined, | ||
}; | ||
if (self.timeout) { | ||
options.timeout = self.timeout; | ||
}; | ||
@@ -147,2 +152,7 @@ | ||
req.on('timeout', () => { | ||
const err = new Error(`Timeout Error: ${options.timeout}ms exceeded`); | ||
callback(err); | ||
}); | ||
req.setHeader('Content-Length', request.length); | ||
@@ -162,2 +172,6 @@ req.setHeader('Content-Type', 'application/json'); | ||
RpcClient.prototype.setTimeout = function (timeout) { | ||
this.timeout = timeout; | ||
} | ||
// For definitions of RPC calls, see various files in: https://github.com/dashpay/dash/tree/master/src | ||
@@ -164,0 +178,0 @@ RpcClient.callspec = { |
{ | ||
"name": "@dashevo/dashd-rpc", | ||
"description": "Dash Client Library to connect to Dash Core (dashd) via RPC", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Stephen Pair", |
@@ -124,3 +124,4 @@ # dashd-rpc | ||
host: '127.0.0.1', | ||
port: 19998 | ||
port: 19998, | ||
timeout: 1000 | ||
}); | ||
@@ -127,0 +128,0 @@ |
@@ -528,2 +528,30 @@ 'use strict'; | ||
}); | ||
it('should throw error when timeout is triggered', (done) => { | ||
var client = new RpcClient({ | ||
user: 'user', | ||
pass: 'pass', | ||
host: 'localhost', | ||
port: 8332, | ||
}); | ||
client.httpOptions = { | ||
timeout: 100 | ||
}; | ||
var requestStub = sinon.stub(client.protocol, 'request').callsFake(function (options, callback) { | ||
var req = new FakeRequest(); | ||
setTimeout(function () { | ||
req.emit('timeout'); | ||
}, options.timeout); | ||
return req; | ||
}); | ||
client.getDifficulty((error, parsedBuf) => { | ||
should.exist(error); | ||
should.not.exist(parsedBuf); | ||
error.message.should.equal(`Timeout Error: ${client.httpOptions.timeout}ms exceeded`); | ||
requestStub.restore(); | ||
done(); | ||
}) | ||
}); | ||
}) |
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
32876
834
146