mirror of https://github.com/status-im/web3.js.git
common changes in requestmanager
This commit is contained in:
parent
d408fb0867
commit
cbab0ae97c
|
@ -33,7 +33,7 @@ var watches = require('./web3/watches');
|
|||
var filter = require('./web3/filter');
|
||||
var utils = require('./utils/utils');
|
||||
var formatters = require('./solidity/formatters');
|
||||
var requestManager = require('./web3/requestmanager');
|
||||
var RequestManager = require('./web3/requestmanager');
|
||||
var c = require('./utils/config');
|
||||
|
||||
/// @returns an array of objects describing web3 api methods
|
||||
|
@ -178,7 +178,7 @@ var web3 = {
|
|||
api: version.version
|
||||
},
|
||||
|
||||
manager: requestManager(),
|
||||
manager: new RequestManager(),
|
||||
providers: {},
|
||||
|
||||
setProvider: function (provider) {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
var jsonrpc = require('./jsonrpc');
|
||||
var utils = require('../utils/utils');
|
||||
var c = require('../utils/config');
|
||||
|
||||
var InvalidResponse = new Error('jsonrpc response is not valid');
|
||||
|
@ -50,6 +51,11 @@ var RequestManager = function() {
|
|||
* @return {Object}
|
||||
*/
|
||||
RequestManager.prototype.send = function (data) {
|
||||
if (!this.provider) {
|
||||
console.error('provider not implemented');
|
||||
return null;
|
||||
}
|
||||
|
||||
var payload = utils.isArray(data) ? jsonrpc.toBatchPayload(data) : jsonrpc.toPayload(data.method, data.params);
|
||||
var result = this.provider.send(payload);
|
||||
|
||||
|
@ -159,8 +165,8 @@ RequestManager.prototype.poll = function () {
|
|||
data.callback(result);
|
||||
});
|
||||
});
|
||||
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT);
|
||||
timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
|
||||
};
|
||||
|
||||
module.exports = requestManager;
|
||||
module.exports = RequestManager;
|
||||
|
||||
|
|
Loading…
Reference in New Issue