diff --git a/src/client/eppo-client.ts b/src/client/eppo-client.ts index 1c5cb7c..5d46635 100644 --- a/src/client/eppo-client.ts +++ b/src/client/eppo-client.ts @@ -108,6 +108,7 @@ export type FlagConfigurationRequestParameters = { pollAfterSuccessfulInitialization?: boolean; pollAfterFailedInitialization?: boolean; throwOnFailedInitialization?: boolean; + skipInitialPoll?: boolean; }; export default class EppoClient implements IEppoClient { @@ -181,6 +182,7 @@ export default class EppoClient implements IEppoClient { this.configurationRequestParameters.pollAfterFailedInitialization ?? false, errorOnFailedStart: this.configurationRequestParameters.throwOnFailedInitialization ?? false, + skipInitialPoll: this.configurationRequestParameters.skipInitialPoll ?? false, }, ); diff --git a/src/poller.spec.ts b/src/poller.spec.ts index a3887a4..1ef8099 100644 --- a/src/poller.spec.ts +++ b/src/poller.spec.ts @@ -22,6 +22,12 @@ describe('poller', () => { }); describe('initial startup', () => { + it('skips initial poll if configured to do so', async () => { + const poller = initPoller(testIntervalMs, noOpCallback, { skipInitialPoll: true }); + await poller.start(); + td.verify(noOpCallback(), { times: 0 }); + }); + it('retries startup poll within same promise', async () => { const pollerRetries = 3; let callCount = 0; diff --git a/src/poller.ts b/src/poller.ts index 209c777..e1eb5f1 100644 --- a/src/poller.ts +++ b/src/poller.ts @@ -23,6 +23,7 @@ export default function initPoller( pollAfterSuccessfulStart?: boolean; errorOnFailedStart?: boolean; pollAfterFailedStart?: boolean; + skipInitialPoll?: boolean; }, ): IPoller { let stopped = false; @@ -34,8 +35,9 @@ export default function initPoller( const start = async () => { stopped = false; let startRequestSuccess = false; - let startAttemptsRemaining = - 1 + (options?.maxStartRetries ?? DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES); + let startAttemptsRemaining = options?.skipInitialPoll + ? 0 + : 1 + (options?.maxStartRetries ?? DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES); let startErrorToThrow = null;