Added pollingInterval to provider. (#132)

This commit is contained in:
Richard Moore 2018-03-15 16:03:20 -04:00
parent 5a9f440c8f
commit 46fd2deb8b
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
6 changed files with 77 additions and 14 deletions

@ -4187,8 +4187,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'getHistory', function(address
return this.resolveName(addressOrName).then(function(address) {
url += '/api?module=account&action=txlist&address=' + address;
url += '&fromBlock=' + startBlock;
url += '&endBlock=' + endBlock;
url += '&startblock=' + startBlock;
url += '&endblock=' + endBlock;
url += '&sort=asc';
return Provider.fetchJSON(url, null, getResult).then(function(result) {
@ -5081,13 +5081,15 @@ function Provider(network) {
self.doPoll();
});
var pollingInterval = 4000;
var poller = null;
Object.defineProperty(this, 'polling', {
get: function() { return (poller != null); },
set: function(value) {
setTimeout(function() {
if (value && !poller) {
poller = setInterval(doPoll, 4000);
poller = setInterval(doPoll, pollingInterval);
} else if (!value && poller) {
clearInterval(poller);
@ -5096,6 +5098,25 @@ function Provider(network) {
}, 0);
}
});
Object.defineProperty(this, 'pollingInterval', {
get: function() { return pollingInterval; },
set: function(value) {
if (typeof(value) !== 'number' || value <= 0 || parseInt(value) != value) {
throw new Error('invalid polling interval');
}
pollingInterval = value;
if (poller) {
clearInterval(poller);
poller = setInterval(doPoll, pollingInterval);
}
}
});
// @TODO: Add .poller which must be an event emitter with a 'start', 'stop' and 'block' event;
// this will be used once we move to the WebSocket or other alternatives to polling
}
function inheritable(parent) {

File diff suppressed because one or more lines are too long

29
dist/ethers.js vendored

@ -9568,7 +9568,7 @@ uuid.unparse = unparse;
module.exports = uuid;
},{"./rng":43}],45:[function(require,module,exports){
module.exports={"version":"3.0.4"}
module.exports={"version":"3.0.6"}
},{}],46:[function(require,module,exports){
'use strict';
@ -9821,8 +9821,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'getHistory', function(address
return this.resolveName(addressOrName).then(function(address) {
url += '/api?module=account&action=txlist&address=' + address;
url += '&fromBlock=' + startBlock;
url += '&endBlock=' + endBlock;
url += '&startblock=' + startBlock;
url += '&endblock=' + endBlock;
url += '&sort=asc';
return Provider.fetchJSON(url, null, getResult).then(function(result) {
@ -10715,13 +10715,15 @@ function Provider(network) {
self.doPoll();
});
var pollingInterval = 4000;
var poller = null;
Object.defineProperty(this, 'polling', {
get: function() { return (poller != null); },
set: function(value) {
setTimeout(function() {
if (value && !poller) {
poller = setInterval(doPoll, 4000);
poller = setInterval(doPoll, pollingInterval);
} else if (!value && poller) {
clearInterval(poller);
@ -10730,6 +10732,25 @@ function Provider(network) {
}, 0);
}
});
Object.defineProperty(this, 'pollingInterval', {
get: function() { return pollingInterval; },
set: function(value) {
if (typeof(value) !== 'number' || value <= 0 || parseInt(value) != value) {
throw new Error('invalid polling interval');
}
pollingInterval = value;
if (poller) {
clearInterval(poller);
poller = setInterval(doPoll, pollingInterval);
}
}
});
// @TODO: Add .poller which must be an event emitter with a 'start', 'stop' and 'block' event;
// this will be used once we move to the WebSocket or other alternatives to polling
}
function inheritable(parent) {

6
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{
"name": "ethers",
"version": "3.0.5",
"version": "3.0.6",
"description": "Ethereum wallet library.",
"main": "index.js",
"scripts": {

@ -476,13 +476,15 @@ function Provider(network) {
self.doPoll();
});
var pollingInterval = 4000;
var poller = null;
Object.defineProperty(this, 'polling', {
get: function() { return (poller != null); },
set: function(value) {
setTimeout(function() {
if (value && !poller) {
poller = setInterval(doPoll, 4000);
poller = setInterval(doPoll, pollingInterval);
} else if (!value && poller) {
clearInterval(poller);
@ -491,6 +493,25 @@ function Provider(network) {
}, 0);
}
});
Object.defineProperty(this, 'pollingInterval', {
get: function() { return pollingInterval; },
set: function(value) {
if (typeof(value) !== 'number' || value <= 0 || parseInt(value) != value) {
throw new Error('invalid polling interval');
}
pollingInterval = value;
if (poller) {
clearInterval(poller);
poller = setInterval(doPoll, pollingInterval);
}
}
});
// @TODO: Add .poller which must be an event emitter with a 'start', 'stop' and 'block' event;
// this will be used once we move to the WebSocket or other alternatives to polling
}
function inheritable(parent) {