Throw when subscription is already present

This commit is contained in:
Leonid Logvinov 2017-11-20 11:10:25 -06:00
parent 2c193a1244
commit 856a5c3369
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4

View File

@ -2,7 +2,7 @@ import * as _ from 'lodash';
import {BigNumber} from 'bignumber.js'; import {BigNumber} from 'bignumber.js';
import {utils} from '../utils/utils'; import {utils} from '../utils/utils';
import {intervalUtils} from '../utils/interval_utils'; import {intervalUtils} from '../utils/interval_utils';
import {SignedOrder} from '../types'; import {SignedOrder, ZeroExError} from '../types';
import {Heap} from '../utils/heap'; import {Heap} from '../utils/heap';
import {ZeroEx} from '../0x'; import {ZeroEx} from '../0x';
@ -26,6 +26,9 @@ export class ExpirationWatcher {
this.orderHashHeapByExpiration = new Heap(scoreFunction); this.orderHashHeapByExpiration = new Heap(scoreFunction);
} }
public subscribe(callback: (orderHash: string) => void): void { public subscribe(callback: (orderHash: string) => void): void {
if (!_.isUndefined(this.callbackIfExists)) {
throw new Error(ZeroExError.SubscriptionAlreadyPresent);
}
this.callbackIfExists = callback; this.callbackIfExists = callback;
this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs, this.pruneExpiredOrders.bind(this), this.orderExpirationCheckingIntervalMs,