From e6139e02b866644500ee7a53a5818ad68f4e2e11 Mon Sep 17 00:00:00 2001 From: Luke Autry Date: Fri, 10 Nov 2017 11:34:17 -0500 Subject: no race, reject from interval cb and clear --- src/0x.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index 2208e5ec8..0ac95fccd 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -294,9 +294,19 @@ export class ZeroEx { */ public async awaitTransactionMinedAsync( txHash: string, pollingIntervalMs = 1000, timeoutMs?: number): Promise { + let timeoutExceeded = false; + if (timeoutMs) { + setTimeout(() => timeoutExceeded = true, timeoutMs); + } + const txReceiptPromise = new Promise( (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { const intervalId = intervalUtils.setAsyncExcludingInterval(async () => { + if (timeoutExceeded) { + clearInterval(intervalId); + return reject(ZeroExError.TransactionMiningTimeout); + } + const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { intervalUtils.clearAsyncExcludingInterval(intervalId); @@ -313,15 +323,6 @@ export class ZeroEx { }, pollingIntervalMs); }); - if (timeoutMs) { - return Promise.race([ - txReceiptPromise, - new Promise((resolve, reject) => { - setTimeout(() => reject(ZeroExError.TransactionMiningTimeout), timeoutMs); - }) - ]); - } - return txReceiptPromise; } /* -- cgit v1.2.3