From 1c542b67770c60b159bc9ed60067e8b7afa08bfe Mon Sep 17 00:00:00 2001 From: mbret Date: Sat, 30 Nov 2024 23:21:00 +0100 Subject: [PATCH] fix: fixed missing idlecallback --- packages/core/src/utils/rxjs.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/src/utils/rxjs.ts b/packages/core/src/utils/rxjs.ts index 143603cc..b8859879 100644 --- a/packages/core/src/utils/rxjs.ts +++ b/packages/core/src/utils/rxjs.ts @@ -70,12 +70,22 @@ export const deferNextResult = (stream: Observable) => { export function idle(): Observable { return new Observable((observer) => { - const handle = requestIdleCallback(() => { + // webkit does not support requestIdleCallback yet + if (window.requestIdleCallback) { + const handle = window.requestIdleCallback(() => { + observer.next() + observer.complete() + }) + + return () => cancelIdleCallback(handle) + } + + const timeout = setTimeout(() => { observer.next() observer.complete() - }) + }, 1) - return () => cancelIdleCallback(handle) + return () => clearTimeout(timeout) }) }