Merged in fix/tracking-pageload-issues (pull request #1630)

fix(tracking): fixes not sending pageview events when promise isn't resolving

* fix(tracking): fixes not sending pageview events when promise isn't resolving

* Refactor


Approved-by: Anton Gunnarsson
This commit is contained in:
Linus Flood
2025-03-25 12:33:04 +00:00
parent 53a610913a
commit 4cd6e7b55b
3 changed files with 105 additions and 71 deletions

View File

@@ -0,0 +1,12 @@
export const promiseWithTimeout = <T>(
promise: Promise<T>,
timeoutMs: number,
fallbackValue: T | undefined = undefined
) => {
return Promise.race([
promise,
new Promise<T | undefined>((resolve) =>
setTimeout(() => resolve(fallbackValue), timeoutMs)
),
])
}