Added fastRetry to polling for JsonRpcSigner to improve polling for sent transactions (#402).

This commit is contained in:
Richard Moore 2019-02-15 13:42:12 -05:00
parent c15a89832b
commit f318fd9cf1
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
2 changed files with 12 additions and 2 deletions

@ -158,7 +158,7 @@ export class JsonRpcSigner extends Signer {
if (tx === null) { return undefined; } if (tx === null) { return undefined; }
return this.provider._wrapTransaction(tx, hash); return this.provider._wrapTransaction(tx, hash);
}); });
}, { onceBlock: this.provider }).catch((error: Error) => { }, { fastRetry: 250, onceBlock: this.provider }).catch((error: Error) => {
(<any>error).transactionHash = hash; (<any>error).transactionHash = hash;
throw error; throw error;
}); });

@ -28,7 +28,8 @@ export type PollOptions = {
floor?: number, floor?: number,
ceiling?: number, ceiling?: number,
interval?: number, interval?: number,
onceBlock?: OnceBlockable onceBlock?: OnceBlockable,
fastRetry?: number
}; };
@ -208,6 +209,8 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
}, options.timeout) }, options.timeout)
} }
let fastTimeout = options.fastRetry || null;
let attempt = 0; let attempt = 0;
function check() { function check() {
return func().then(function(result) { return func().then(function(result) {
@ -227,6 +230,13 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
if (timeout < options.floor) { timeout = options.floor; } if (timeout < options.floor) { timeout = options.floor; }
if (timeout > options.ceiling) { timeout = options.ceiling; } if (timeout > options.ceiling) { timeout = options.ceiling; }
// Fast Timeout, means we quickly try again the first time
if (fastTimeout) {
attempt--;
timeout = fastTimeout;
fastTimeout = null;
}
setTimeout(check, timeout); setTimeout(check, timeout);
} }