Skip to content

Commit 0846d72

Browse files
committed
double invocation should be avoidable via canInitialize
1 parent 9393a5d commit 0846d72

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/feature-toggles.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ class FeatureToggles {
10091009
return await this.__initializePromise;
10101010
}
10111011

1012+
get canInitialize() {
1013+
return !this.__initializePromise;
1014+
}
1015+
10121016
// ========================================
10131017
// END OF INITIALIZE SECTION
10141018
// ========================================

test/integration-local/feature-toggles.integration.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ describe("local integration test", () => {
7474
};
7575

7676
test("init throws for double invocation", async () => {
77-
await toggles.initializeFeatures();
77+
let initPromise;
78+
expect(toggles.canInitialize).toBe(true);
79+
initPromise = toggles.initializeFeatures();
80+
expect(toggles.canInitialize).toBe(false);
7881
await expect(toggles.initializeFeatures()).rejects.toMatchInlineSnapshot(
7982
`[FeatureTogglesError: already initialized]`
8083
);
84+
await initPromise;
8185
});
8286

8387
test("init throws for non-existing filepaths", async () => {

0 commit comments

Comments
 (0)