mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-22 11:08:33 +00:00
improved requestmanager
This commit is contained in:
parent
c8f8ba8086
commit
ecd0b7776f
@ -39,9 +39,11 @@ var RequestManager = function (provider) {
|
||||
this.provider = provider;
|
||||
this.polls = {};
|
||||
this.timeout = null;
|
||||
this.isPolling = false;
|
||||
|
||||
this.poll();
|
||||
if(this.provider) {
|
||||
this.poll();
|
||||
this.isPolling = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -130,6 +132,11 @@ RequestManager.prototype.setProvider = function (p) {
|
||||
this.provider = p;
|
||||
|
||||
if (this.provider && !this.isPolling) {
|
||||
if (this.timeout) {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
this.poll();
|
||||
this.isPolling = true;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
"gulp-uglify": ">=1.2.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"jshint": ">=2.5.0",
|
||||
"mocha": ">=2.1.0",
|
||||
"mocha": ">=2.3.3",
|
||||
"sandboxed-module": "^2.0.2",
|
||||
"vinyl-source-stream": "^1.1.0"
|
||||
},
|
||||
|
@ -15,9 +15,9 @@ var runTests = function (obj, method, tests) {
|
||||
it('sync test: ' + index, function () {
|
||||
|
||||
// given
|
||||
web3.reset();
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset();
|
||||
provider.injectResult(test.result);
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
@ -45,9 +45,9 @@ var runTests = function (obj, method, tests) {
|
||||
it('async test: ' + index, function (done) {
|
||||
|
||||
// given
|
||||
web3.reset();
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset();
|
||||
provider.injectResult(test.result);
|
||||
provider.injectValidation(function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
|
@ -204,9 +204,9 @@ describe('web3.eth.contract', function() {
|
||||
});
|
||||
|
||||
it('should create contract with nondefault constructor', function (done) {
|
||||
web3.reset(); // reset different polls
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset(); // reset different polls
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
|
||||
var description = [{
|
||||
|
@ -27,10 +27,11 @@ describe('eth', function () {
|
||||
tests.forEach(function (test, index) {
|
||||
it('property test: ' + index, function (done) {
|
||||
|
||||
|
||||
// given
|
||||
web3.reset();
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
web3.reset();
|
||||
provider.injectBatchResults(test.result);
|
||||
provider.injectValidation(function(payload) {
|
||||
assert.equal(payload[0].jsonrpc, '2.0', 'failed');
|
||||
@ -42,6 +43,7 @@ describe('eth', function () {
|
||||
|
||||
// TODO results seem to be overwritten
|
||||
|
||||
|
||||
// call
|
||||
var syncing = web3.eth[method](function(e, res){
|
||||
if(count === 1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user