diff options
author | Jacob Evans <jacob@dekz.net> | 2017-11-15 00:21:00 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2017-11-15 00:21:00 +0800 |
commit | 752603284de28f8d966fe61a52d0ffe5dd8afd6a (patch) | |
tree | 111c52f4fff2c314ef01e83bc8e6fac3fdadc05f /packages | |
parent | 8f4be963b2f16351b6f55513e190e1e287328911 (diff) | |
download | dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar.gz dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar.bz2 dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar.lz dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar.xz dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.tar.zst dexon-sol-tools-752603284de28f8d966fe61a52d0ffe5dd8afd6a.zip |
Remove Async subscribe callbacks from OrderWatcher
Diffstat (limited to 'packages')
-rw-r--r-- | packages/0x.js/src/order_watcher/order_state_watcher.ts | 14 | ||||
-rw-r--r-- | packages/0x.js/src/types.ts | 4 |
2 files changed, 8 insertions, 10 deletions
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 2b9d7997e..80f323017 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -52,7 +52,7 @@ interface OrderByOrderHash { export class OrderStateWatcher { private _orderByOrderHash: OrderByOrderHash = {}; private _dependentOrderHashes: DependentOrderHashes = {}; - private _callbackIfExistsAsync?: OnOrderStateChangeCallback; + private _callbackIfExists?: OnOrderStateChangeCallback; private _eventWatcher: EventWatcher; private _web3Wrapper: Web3Wrapper; private _abiDecoder: AbiDecoder; @@ -106,22 +106,22 @@ export class OrderStateWatcher { */ public subscribe(callback: OnOrderStateChangeCallback): void { assert.isFunction('callback', callback); - if (!_.isUndefined(this._callbackIfExistsAsync)) { + if (!_.isUndefined(this._callbackIfExists)) { throw new Error(ZeroExError.SubscriptionAlreadyPresent); } - this._callbackIfExistsAsync = callback; + this._callbackIfExists = callback; this._eventWatcher.subscribe(this._onEventWatcherCallbackAsync.bind(this)); } /** * Ends an orderStateWatcher subscription. */ public unsubscribe(): void { - if (_.isUndefined(this._callbackIfExistsAsync)) { + if (_.isUndefined(this._callbackIfExists)) { throw new Error(ZeroExError.SubscriptionNotFound); } this._balanceAndProxyAllowanceLazyStore.deleteAll(); this._orderFilledCancelledLazyStore.deleteAll(); - delete this._callbackIfExistsAsync; + delete this._callbackIfExists; this._eventWatcher.unsubscribe(); } private async _onEventWatcherCallbackAsync(log: LogEvent): Promise<void> { @@ -204,10 +204,10 @@ export class OrderStateWatcher { // Most of these calls will never reach the network because the data is fetched from stores // and only updated when cache is invalidated const orderState = await this._orderStateUtils.getOrderStateAsync(signedOrder); - if (_.isUndefined(this._callbackIfExistsAsync)) { + if (_.isUndefined(this._callbackIfExists)) { break; // Unsubscribe was called } - await this._callbackIfExistsAsync(orderState); + this._callbackIfExists(orderState); } } private addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string) { diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 04dfe3b0d..91e3c0f20 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -501,9 +501,7 @@ export interface OrderStateInvalid { export type OrderState = OrderStateValid|OrderStateInvalid; -export type OnOrderStateChangeCallbackSync = (orderState: OrderState) => void; -export type OnOrderStateChangeCallbackAsync = (orderState: OrderState) => Promise<void>; -export type OnOrderStateChangeCallback = OnOrderStateChangeCallbackAsync|OnOrderStateChangeCallbackSync; +export type OnOrderStateChangeCallback = (orderState: OrderState) => void; export interface TransactionReceipt { blockHash: string; |