Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk-common",
"version": "4.15.1",
"version": "4.15.2",
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
"main": "dist/index.js",
"files": [
Expand Down
11 changes: 10 additions & 1 deletion src/poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ export default function initPoller(
stopped = true;
if (nextTimer) {
clearTimeout(nextTimer);
nextTimer = undefined;
}
logger.info('Eppo SDK polling stopped');
}
};

async function poll() {
if (stopped) {
if (nextTimer) {
clearTimeout(nextTimer);
nextTimer = undefined;
}
Comment on lines +108 to +111
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other tests that I can write to check that stopping the poller works. We already have this.

it('stops polling', async () => {
const poller = initPoller(testIntervalMs, noOpCallback, { pollAfterSuccessfulStart: true });
await poller.start();
td.verify(noOpCallback(), { times: 1 });
poller.stop();
await jest.advanceTimersByTimeAsync(testIntervalMs * 10);
td.verify(noOpCallback(), { times: 1 });
});

Any tips? @aarsilv

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a test where we call stopPolling() immediately after making the poller but that may be overkill

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jest.getTimerCount may be an option to check how many timers are remaining.

return;
}

Expand Down Expand Up @@ -134,10 +139,14 @@ export default function initPoller(
`Eppo SDK reached maximum of ${failedAttempts} failed polling attempts. Stopping polling`,
);
stop();
return;
}
}

setTimeout(poll, nextPollMs);
// Check stopped state again before setting up next timer to handle race condition
if (!stopped) {
nextTimer = setTimeout(poll, nextPollMs);
}
}

return {
Expand Down
Loading