diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-23 01:44:34 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-23 01:44:34 +0800 |
commit | 3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8 (patch) | |
tree | 77aef02c1e862b4eaeeeb08b12a1ec8da8f54499 /packages/0x.js/src | |
parent | beed223281115152e2d4282fa2c2e76515a98f45 (diff) | |
download | dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.gz dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.bz2 dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.lz dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.xz dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.tar.zst dexon-0x-contracts-3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8.zip |
Refactor while condition
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/order_watcher/expiration_watcher.ts | 18 |
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]; |