diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-21 06:14:40 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-21 06:14:40 +0800 |
commit | 9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f (patch) | |
tree | e2194e92ee6ab833b2a5bcee1a7d2641e9c005d1 /packages | |
parent | d39c0bee39a7bc9cbab6810e8b1b42dfe2e6cf09 (diff) | |
download | dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar.gz dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar.bz2 dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar.lz dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar.xz dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.tar.zst dexon-sol-tools-9745d5348c7cbef0d0b16fafa2453acfc6cb2c1f.zip |
Pass callback down
Diffstat (limited to 'packages')
-rw-r--r-- | packages/0x.js/src/order_watcher/expiration_watcher.ts | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index 7d6f8df65..933cb6f1d 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -16,7 +16,6 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50; export class ExpirationWatcher { private orderHashRBTreeByExpiration: RBTree<string>; private expiration: {[orderHash: string]: BigNumber} = {}; - private callbackIfExists?: (orderHash: string) => void; private orderExpirationCheckingIntervalMs: number; private expirationMarginMs: number; private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer; @@ -31,12 +30,11 @@ export class ExpirationWatcher { this.orderHashRBTreeByExpiration = new RBTree(comparator); } public subscribe(callback: (orderHash: string) => void): void { - if (!_.isUndefined(this.callbackIfExists)) { + if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) { throw new Error(ZeroExError.SubscriptionAlreadyPresent); } - this.callbackIfExists = callback; this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( - this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, + this.pruneExpiredOrders.bind(this, callback), this.orderExpirationCheckingIntervalMs, ); } public unsubscribe(): void { @@ -44,7 +42,6 @@ export class ExpirationWatcher { throw new Error(ZeroExError.SubscriptionNotFound); } intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists); - delete this.callbackIfExists; delete this.orderExpirationCheckingIntervalIdIfExists; } public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void { @@ -55,19 +52,18 @@ export class ExpirationWatcher { this.orderHashRBTreeByExpiration.remove(orderHash); delete this.expiration[orderHash]; } - private pruneExpiredOrders(): void { + private pruneExpiredOrders(callback: (orderHash: string) => void): void { const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs(); while ( this.orderHashRBTreeByExpiration.size !== 0 && this.expiration[this.orderHashRBTreeByExpiration.min()].lessThan( currentUnixTimestampMs.plus(this.expirationMarginMs), - ) && - !_.isUndefined(this.callbackIfExists) + ) ) { const orderHash = this.orderHashRBTreeByExpiration.min(); this.orderHashRBTreeByExpiration.remove(orderHash); delete this.expiration[orderHash]; - this.callbackIfExists(orderHash); + callback(orderHash); } } } |