diff options
author | Luke Autry <lukeautry@gmail.com> | 2017-11-11 00:34:17 +0800 |
---|---|---|
committer | Luke Autry <lukeautry@gmail.com> | 2017-11-11 00:34:17 +0800 |
commit | e6139e02b866644500ee7a53a5818ad68f4e2e11 (patch) | |
tree | 6207c335c30b047608ac17f62f2c05a0b5332f84 | |
parent | 583b92e672d5ff644d79e3a75dd8c9b6cc85932a (diff) | |
download | dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.gz dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.bz2 dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.lz dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.xz dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.zst dexon-0x-contracts-e6139e02b866644500ee7a53a5818ad68f4e2e11.zip |
no race, reject from interval cb and clear
-rw-r--r-- | src/0x.ts | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -294,9 +294,19 @@ export class ZeroEx { */ public async awaitTransactionMinedAsync( txHash: string, pollingIntervalMs = 1000, timeoutMs?: number): Promise<TransactionReceiptWithDecodedLogs> { + 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<TransactionReceiptWithDecodedLogs>((resolve, reject) => { - setTimeout(() => reject(ZeroExError.TransactionMiningTimeout), timeoutMs); - }) - ]); - } - return txReceiptPromise; } /* |