From 856a5c3369c0248ec32924b25ec77dce6b4e1071 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 20 Nov 2017 11:10:25 -0600 Subject: Throw when subscription is already present --- packages/0x.js/src/order_watcher/expiration_watcher.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts index acc7e7e5d..6d9556336 100644 --- a/packages/0x.js/src/order_watcher/expiration_watcher.ts +++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash'; import {BigNumber} from 'bignumber.js'; import {utils} from '../utils/utils'; import {intervalUtils} from '../utils/interval_utils'; -import {SignedOrder} from '../types'; +import {SignedOrder, ZeroExError} from '../types'; import {Heap} from '../utils/heap'; import {ZeroEx} from '../0x'; @@ -26,6 +26,9 @@ export class ExpirationWatcher { this.orderHashHeapByExpiration = new Heap(scoreFunction); } public subscribe(callback: (orderHash: string) => void): void { + if (!_.isUndefined(this.callbackIfExists)) { + throw new Error(ZeroExError.SubscriptionAlreadyPresent); + } this.callbackIfExists = callback; this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, -- cgit v1.2.3