Browse Source

add delay in async scan execution

activeAddress
Ivan Socolsky 10 years ago
parent
commit
d27edeaa7e
  1. 7
      lib/lock.js
  2. 4
      lib/server.js
  3. 9
      test/integration/server.js

7
lib/lock.js

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

4
lib/server.js

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

9
test/integration/server.js

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

Loading…
Cancel
Save