Skip to content

Commit

Permalink
fix: fixed missing idlecallback
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Nov 30, 2024
1 parent 601503c commit 1c542b6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/core/src/utils/rxjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,22 @@ export const deferNextResult = <T>(stream: Observable<T>) => {

export function idle(): Observable<void> {
return new Observable<void>((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)
})
}

Expand Down

0 comments on commit 1c542b6

Please sign in to comment.