add delay in async scan execution

This commit is contained in:
Ivan Socolsky 2015-04-03 15:43:22 -03:00
parent 6c43bfb7f6
commit d27edeaa7e
3 changed files with 8 additions and 12 deletions

View File

@ -1,13 +1,14 @@
var _ = require('lodash');
var $ = require('preconditions').singleton();
var locks = {};
var Lock = function () {
var Lock = function() {
this.taken = false;
this.queue = [];
};
Lock.prototype.free = function () {
Lock.prototype.free = function() {
if (this.queue.length > 0) {
var f = this.queue.shift();
f(this);
@ -16,7 +17,7 @@ Lock.prototype.free = function () {
}
};
Lock.get = function (key, callback) {
Lock.get = function(key, callback) {
if (_.isUndefined(locks[key])) {
locks[key] = new Lock();
}

View File

@ -1230,9 +1230,9 @@ WalletService.prototype.startScan = function(opts, cb) {
setTimeout(function() {
self.scan(opts, scanFinished);
}, 0);
}, 100);
return cb()
return cb();
});
});
};

View File

@ -2688,13 +2688,12 @@ describe('Wallet service', function() {
});
it('should start multiple asynchronous scans for different wallets', function(done) {
helpers.stubAddressActivity(['3K2VWMXheGZ4qG35DyGjA2dLeKfaSr534A']);
WalletService.scanConfig.SCAN_WINDOW = 2;
WalletService.scanConfig.SCAN_WINDOW = 1;
var scans = 0;
WalletService.onNotification(function(n) {
if (n.type == 'ScanFinished') {
scans++;
// console.log('*** [server.js ln2697] n:', n); // TODO
if (scans == 2) done();
}
});
@ -2718,17 +2717,13 @@ describe('Wallet service', function() {
server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err);
helpers.getAuthServer(result.copayerId, function(server2) {
server.startScan({
includeCopayerBranches: true
}, function(err) {
server.startScan({}, function(err) {
should.not.exist(err);
scans.should.equal(0);
// console.log('*** [server.js ln2726] scans:', scans); // TODO
});
server2.startScan({}, function(err) {
should.not.exist(err);
scans.should.equal(0);
// console.log('*** [server.js ln2731] scans:', scans); // TODO
});
scans.should.equal(0);
});