Skip to content

Commit

Permalink
fix: Cleanup timeout timer for waitForInitialization (#478)
Browse files Browse the repository at this point in the history
Use the new cancelable timer to ensure that the handle gets cleaned up.
  • Loading branch information
kinyoklion authored Jun 4, 2024
1 parent 24ecf1d commit fccbfac
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/shared/sdk-server/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable class-methods-use-this */
import {
cancelableTimedPromise,
ClientContext,
Context,
internal,
Expand All @@ -11,7 +12,6 @@ import {
LDTimeoutError,
Platform,
subsystem,
timedPromise,
TypeValidators,
} from '@launchdarkly/js-sdk-common';

Expand Down Expand Up @@ -911,8 +911,11 @@ export default class LDClientImpl implements LDClient {
logger?: LDLogger,
): Promise<LDClient> {
if (timeout) {
const timeoutPromise = timedPromise(timeout, 'waitForInitialization');
return Promise.race([basePromise, timeoutPromise.then(() => this)]).catch((reason) => {
const cancelableTimeout = cancelableTimedPromise(timeout, 'waitForInitialization');
return Promise.race([
basePromise.then(() => cancelableTimeout.cancel()).then(() => this),
cancelableTimeout.promise.then(() => this),
]).catch((reason) => {
if (reason instanceof LDTimeoutError) {
logger?.error(reason.message);
}
Expand Down

0 comments on commit fccbfac

Please sign in to comment.