Skip to content

Commit b7b3193

Browse files
chore: lazy-load split client so tests dont stay-alive async
1 parent 7d606b5 commit b7b3193

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/util/splitClient.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export function createSplitClient(apiKey: string, proxyUrl?: string) {
3838
}
3939

4040
/**
41-
* Singleton Split.io client instance
41+
* Lazy-loaded Split.io client instance
4242
*/
43-
export const splitClient = createSplitClient(SPLIT_API_KEY, SPLIT_PROXY_URL);
43+
let internalSplitClient: SplitIO.IClient | null = null;
44+
45+
export const splitClient = {
46+
getTreatment: (key: string, splitName: string) => {
47+
if (!internalSplitClient) {
48+
internalSplitClient = createSplitClient(SPLIT_API_KEY, SPLIT_PROXY_URL);
49+
}
50+
return internalSplitClient.getTreatment(key, splitName);
51+
},
52+
};

0 commit comments

Comments
 (0)