diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-17 15:32:08 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-17 15:32:08 +0100 |
commit | c8576b433d8442694e0427301cf061aade0a6f8e (patch) | |
tree | 6dd5544d7a41fbd73dd99c676735a4b6d06c5591 /src | |
parent | d64861acec41927787dbe65ccd2067cd900b1f67 (diff) | |
download | wallet-core-c8576b433d8442694e0427301cf061aade0a6f8e.tar.xz |
per-exchange throttling
Diffstat (limited to 'src')
-rw-r--r-- | src/types.ts | 2 | ||||
-rw-r--r-- | src/wallet.ts | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/types.ts b/src/types.ts index 9de769dfe..b04453767 100644 --- a/src/types.ts +++ b/src/types.ts @@ -509,7 +509,7 @@ export type PayCoinInfo = Array<{ updatedCoin: CoinRecord, sig: CoinPaySig }>; export namespace Amounts { - export const fractionalBase = 1e6; + export const fractionalBase = 1e8; export interface Result { amount: AmountJson; diff --git a/src/wallet.ts b/src/wallet.ts index 354072130..fc9fd823b 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -380,6 +380,7 @@ export class Wallet { public cryptoApi: CryptoApi; private processPreCoinConcurrent = 0; + private processPreCoinThrottle: {[url: string]: number} = {}; /** * Set of identifiers for running operations. @@ -728,7 +729,7 @@ export class Wallet { private async processPreCoin(preCoin: PreCoinRecord, retryDelayMs = 200): Promise<void> { - if (this.processPreCoinConcurrent >= 1) { + if (this.processPreCoinConcurrent >= 4 || this.processPreCoinThrottle[preCoin.exchangeBaseUrl]) { console.log("delaying processPreCoin"); setTimeout(() => this.processPreCoin(preCoin, retryDelayMs * 2), retryDelayMs); @@ -793,6 +794,8 @@ export class Wallet { let nextRetryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60); setTimeout(() => this.processPreCoin(preCoin, nextRetryDelayMs), retryDelayMs); + this.processPreCoinThrottle[preCoin.exchangeBaseUrl] = (this.processPreCoinThrottle[preCoin.exchangeBaseUrl] || 0) + 1; + setTimeout(() => {this.processPreCoinThrottle[preCoin.exchangeBaseUrl]--; }, retryDelayMs); } finally { this.processPreCoinConcurrent--; } |