From 6012926e8278bed55b173a8e8380231c75a1a48c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 10 Nov 2017 18:07:11 -0500 Subject: Throw if trying to subscribe multiple times --- src/order_watcher/event_watcher.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/order_watcher') diff --git a/src/order_watcher/event_watcher.ts b/src/order_watcher/event_watcher.ts index 286872a6f..c11b78f2e 100644 --- a/src/order_watcher/event_watcher.ts +++ b/src/order_watcher/event_watcher.ts @@ -1,7 +1,12 @@ import * as Web3 from 'web3'; import * as _ from 'lodash'; import {Web3Wrapper} from '../web3_wrapper'; -import {BlockParamLiteral, EventCallback, EventWatcherCallback} from '../types'; +import { + BlockParamLiteral, + EventCallback, + EventWatcherCallback, + ZeroExError, +} from '../types'; import {AbiDecoder} from '../utils/abi_decoder'; import {intervalUtils} from '../utils/interval_utils'; import {assert} from '../utils/assert'; @@ -28,6 +33,9 @@ export class EventWatcher { } public subscribe(callback: EventWatcherCallback): void { assert.isFunction('callback', callback); + if (!_.isUndefined(this._callbackIfExistsAsync)) { + throw new Error(ZeroExError.SubscriptionAlreadyPresent); + } this._callbackIfExistsAsync = callback; this._intervalIdIfExists = intervalUtils.setAsyncExcludingInterval( this._pollForBlockchainEventsAsync.bind(this), this._pollingIntervalMs, -- cgit v1.2.3