aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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];