aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-23 01:44:34 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-23 01:44:34 +0800
commit3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8 (patch)
tree77aef02c1e862b4eaeeeb08b12a1ec8da8f54499 /packages
parentbeed223281115152e2d4282fa2c2e76515a98f45 (diff)
downloaddexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.gz
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.bz2
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.lz
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.xz
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.zst
dexon-sol-tools-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.zip
Refactor while condition
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/order_watcher/expiration_watcher.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts
index 5aa8b3d17..862714cc5 100644
--- a/packages/0x.js/src/order_watcher/expiration_watcher.ts
+++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts
@@ -54,13 +54,19 @@ export class ExpirationWatcher {
}
private async pruneExpiredOrdersAsync(callbackAsync: (orderHash: string) => Promise<void>): Promise<void> {
const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs();
- while (
- this.orderHashByExpirationRBTree.size !== 0 &&
- this.expiration[this.orderHashByExpirationRBTree.min()].lessThan(
+ while (true) {
+ const noOrdersLeft = this.orderHashByExpirationRBTree.size === 0;
+ if (noOrdersLeft) {
+ break;
+ }
+ const nextOrderHashToExpire = this.orderHashByExpirationRBTree.min();
+ const noExpiredOrdersLeft = this.expiration[nextOrderHashToExpire].greaterThan(
currentUnixTimestampMs.plus(this.expirationMarginMs),
- ) &&
- !_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)
- ) {
+ );
+ const noActiveSubscription = _.isUndefined(this.orderExpirationCheckingIntervalIdIfExists);
+ if (noExpiredOrdersLeft || noActiveSubscription) {
+ break;
+ }
const orderHash = this.orderHashByExpirationRBTree.min();
this.orderHashByExpirationRBTree.remove(orderHash);
delete this.expiration[orderHash];