From 7f082b076f7a4f278cb3b15b06fc179118d9deb1 Mon Sep 17 00:00:00 2001 From: kamilkifer <47425451+kamilkifer@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:50:21 +0100 Subject: [PATCH] chore: resolve promise and fix lint --- src/main.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 617c57d..91f7ff4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -126,7 +126,7 @@ export function reset(): void { _config.onVariationChange(); } -//auto resolves the promise after 2 seconds if the condition is not met - stops a hanging promise +// auto resolves the promise after 2 seconds if the condition is not met - stops a hanging promise const waitUntil = (condition: () => any, checkInterval = 100, timeout = 2000) => { return new Promise((resolve, reject) => { const startTime = Date.now(); @@ -138,20 +138,21 @@ const waitUntil = (condition: () => any, checkInterval = 100, timeout = 2000) => } else if (Date.now() - startTime >= timeout) { clearInterval(interval); clearTimeout(safetyTimeout); - reject(new Error("Timeout")); + resolve(); } }, checkInterval); const safetyTimeout = setTimeout(() => { clearInterval(interval); - reject(new Error("Timeout")); + resolve(); }, timeout); }); }; export async function shouldShowUI() { - // cookie name is provided from split test package user config. Ensures it's loaded before calling the shouldShowUI function - await waitUntil(() => _config.cookieName === "trustpilotABTest").catch(()=>{}); + // cookie name is provided from split test package user config. + // Ensures it's loaded before calling the shouldShowUI function + await waitUntil(() => _config.cookieName === 'trustpilotABTest'); const promises = [ _config.globalCondition(userAgentInfo), _config.uiCondition(userAgentInfo),