Skip to content

Commit

Permalink
Allow overriding pollingInterval in JsonRpcProvider constructor (via …
Browse files Browse the repository at this point in the history
…discord).
  • Loading branch information
ricmoo committed Jul 28, 2023
1 parent 78538eb commit f42f258
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { PollingEventSubscriber } from "./subscriber-polling.js";
import type { TypedDataDomain, TypedDataField } from "../hash/index.js";
import type { TransactionLike } from "../transaction/index.js";

import type { AbstractProviderOptions, PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js";
import type { PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js";
import type { Networkish } from "./network.js";
import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js";
import type { Signer } from "./signer.js";
Expand Down Expand Up @@ -196,6 +196,7 @@ export type JsonRpcApiProviderOptions = {
batchMaxCount?: number;

cacheTimeout?: number;
pollingInterval?: number;
};

const defaultOptions = {
Expand All @@ -206,7 +207,8 @@ const defaultOptions = {
batchMaxSize: (1 << 20), // 1Mb
batchMaxCount: 100, // 100 requests

cacheTimeout: 250
cacheTimeout: 250,
pollingInterval: 4000
}

/**
Expand Down Expand Up @@ -543,11 +545,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
}

constructor(network?: Networkish, options?: JsonRpcApiProviderOptions) {
const superOptions: AbstractProviderOptions = { };
if (options && options.cacheTimeout != null) {
superOptions.cacheTimeout = options.cacheTimeout;
}
super(network, superOptions);
super(network, options);

this.#nextId = 1;
this.#options = Object.assign({ }, defaultOptions, options || { });
Expand Down Expand Up @@ -1079,6 +1077,12 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
}
}

// @TODO: remove this in v7, it is not exported because this functionality
// is exposed in the JsonRpcApiProvider by setting polling to true. It should
// be safe to remove regardless, because it isn't reachable, but just in case.
/**
* @_ignore:
*/
export abstract class JsonRpcApiPollingProvider extends JsonRpcApiProvider {
#pollingInterval: number;
constructor(network?: Networkish, options?: JsonRpcApiProviderOptions) {
Expand Down

0 comments on commit f42f258

Please sign in to comment.