From 3fc0eae4c0d66ff2cf9bffc8bc646b5aeb0c13b8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 11:44:34 -0600 Subject: Refactor while condition --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'packages') 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): Promise { 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]; -- cgit