give lock preference to the new instance

This commit is contained in:
Matias Alejo Garcia 2014-08-15 12:49:16 -04:00
parent 18aadede29
commit 1a5a2916c2
3 changed files with 12 additions and 8 deletions

View File

@ -89,7 +89,7 @@ path: '/',
verbose: 1,
// will duplicate itself after each try
reconnectDelay: 5000,
idleDurationMin: 1
idleDurationMin: 4
},
// blockchain service API config

View File

@ -10,7 +10,7 @@ function WalletLock(storage, walletId, timeoutMin) {
this.storage = storage;
this.timeoutMin = timeoutMin || 5;
this.key = WalletLock._keyFor(walletId);
this.keepAlive();
this._setLock();
}
WalletLock._keyFor = function(walletId) {
return 'lock' + '::' + walletId;
@ -29,17 +29,21 @@ WalletLock.prototype._isLockedByOther = function() {
};
WalletLock.prototype._setLock = function() {
this.storage.setGlobal(this.key, {
sessionId: this.sessionId,
expireTs: Date.now() + this.timeoutMin * 60 * 1000,
});
};
WalletLock.prototype.keepAlive = function() {
preconditions.checkState(this.sessionId);
var t = this._isLockedByOther();
if (t)
throw new Error('Wallet is already open. Close it to proceed or wait '+ t + ' seconds if you close it already' );
this.storage.setGlobal(this.key, {
sessionId: this.sessionId,
expireTs: Date.now() + this.timeoutMin * 60 * 1000,
});
this._setLock();
};

View File

@ -77,7 +77,7 @@ angular
var timeout = config.wallet.idleDurationMin * 60 || 300;
$idleProvider.idleDuration(timeout); // in seconds
$idleProvider.warningDuration(20); // in seconds
$keepaliveProvider.interval(5); // in seconds
$keepaliveProvider.interval(2); // in seconds
})
.run(function($rootScope, $location, $idle) {
$idle.watch();