aboutsummaryrefslogtreecommitdiffstats
path: root/src/0x.ts
diff options
context:
space:
mode:
authorLuke Autry <lukeautry@gmail.com>2017-11-11 00:34:17 +0800
committerLuke Autry <lukeautry@gmail.com>2017-11-11 00:34:17 +0800
commite6139e02b866644500ee7a53a5818ad68f4e2e11 (patch)
tree6207c335c30b047608ac17f62f2c05a0b5332f84 /src/0x.ts
parent583b92e672d5ff644d79e3a75dd8c9b6cc85932a (diff)
downloaddexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.gz
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.bz2
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.lz
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.xz
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.tar.zst
dexon-sol-tools-e6139e02b866644500ee7a53a5818ad68f4e2e11.zip
no race, reject from interval cb and clear
Diffstat (limited to 'src/0x.ts')
-rw-r--r--src/0x.ts19
1 files changed, 10 insertions, 9 deletions
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<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;
}
/*