Skip to content

Commit fccbfac

Browse files
authored
fix: Cleanup timeout timer for waitForInitialization (#478)
Use the new cancelable timer to ensure that the handle gets cleaned up.
1 parent 24ecf1d commit fccbfac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/shared/sdk-server/src/LDClientImpl.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable class-methods-use-this */
22
import {
3+
cancelableTimedPromise,
34
ClientContext,
45
Context,
56
internal,
@@ -11,7 +12,6 @@ import {
1112
LDTimeoutError,
1213
Platform,
1314
subsystem,
14-
timedPromise,
1515
TypeValidators,
1616
} from '@launchdarkly/js-sdk-common';
1717

@@ -911,8 +911,11 @@ export default class LDClientImpl implements LDClient {
911911
logger?: LDLogger,
912912
): Promise<LDClient> {
913913
if (timeout) {
914-
const timeoutPromise = timedPromise(timeout, 'waitForInitialization');
915-
return Promise.race([basePromise, timeoutPromise.then(() => this)]).catch((reason) => {
914+
const cancelableTimeout = cancelableTimedPromise(timeout, 'waitForInitialization');
915+
return Promise.race([
916+
basePromise.then(() => cancelableTimeout.cancel()).then(() => this),
917+
cancelableTimeout.promise.then(() => this),
918+
]).catch((reason) => {
916919
if (reason instanceof LDTimeoutError) {
917920
logger?.error(reason.message);
918921
}

0 commit comments

Comments
 (0)