Skip to content

Commit

Permalink
Added fastRetry to polling for JsonRpcSigner to improve polling for s…
Browse files Browse the repository at this point in the history
…ent transactions (#402).
  • Loading branch information
ricmoo committed Feb 15, 2019
1 parent c15a898 commit f318fd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src.ts/providers/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
12 changes: 11 additions & 1 deletion src.ts/utils/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type PollOptions = {
floor?: number,
ceiling?: number,
interval?: number,
onceBlock?: OnceBlockable
onceBlock?: OnceBlockable,
fastRetry?: number
};


Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down

0 comments on commit f318fd9

Please sign in to comment.