Added fastRetry to polling for JsonRpcSigner to improve polling for sent transactions (#402).
This commit is contained in:
parent
c15a89832b
commit
f318fd9cf1
@ -158,7 +158,7 @@ export class JsonRpcSigner extends Signer {
|
||||
if (tx === null) { return undefined; }
|
||||
return this.provider._wrapTransaction(tx, hash);
|
||||
});
|
||||
}, { onceBlock: this.provider }).catch((error: Error) => {
|
||||
}, { fastRetry: 250, onceBlock: this.provider }).catch((error: Error) => {
|
||||
(<any>error).transactionHash = hash;
|
||||
throw error;
|
||||
});
|
||||
|
@ -28,7 +28,8 @@ export type PollOptions = {
|
||||
floor?: number,
|
||||
ceiling?: 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)
|
||||
}
|
||||
|
||||
let fastTimeout = options.fastRetry || null;
|
||||
|
||||
let attempt = 0;
|
||||
function check() {
|
||||
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.ceiling) { timeout = options.ceiling; }
|
||||
|
||||
// Fast Timeout, means we quickly try again the first time
|
||||
if (fastTimeout) {
|
||||
attempt--;
|
||||
timeout = fastTimeout;
|
||||
fastTimeout = null;
|
||||
}
|
||||
|
||||
setTimeout(check, timeout);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user