improved requestmanager

This commit is contained in:
Fabian Vogelsteller 2015-10-08 13:43:53 +02:00
parent c8f8ba8086
commit ecd0b7776f
5 changed files with 16 additions and 7 deletions

View File

@ -39,9 +39,11 @@ var RequestManager = function (provider) {
this.provider = provider;
this.polls = {};
this.timeout = null;
this.isPolling = false;
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;
}

View File

@ -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"
},

View File

@ -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');

View File

@ -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 = [{

View File

@ -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) {