fix requestIdleCallback not defined in Edge (#180)
This commit is contained in:
parent
682cb6f40e
commit
79b848df2c
|
@ -8,13 +8,19 @@ import { mark, stop } from './marks'
|
|||
const taskQueue = new Queue()
|
||||
let runningRequestIdleCallback = false
|
||||
|
||||
function getRIC () {
|
||||
// we load polyfills asynchronously, so there's a tiny chance this is not defined
|
||||
return typeof requestIdleCallback !== 'undefined' ? requestIdleCallback : setTimeout
|
||||
}
|
||||
|
||||
function runTasks (deadline) {
|
||||
mark('scheduleIdleTask:runTasks()')
|
||||
while (taskQueue.length && deadline.timeRemaining() > 0) {
|
||||
taskQueue.shift()()
|
||||
}
|
||||
if (taskQueue.length) {
|
||||
requestIdleCallback(runTasks)
|
||||
let rIC = getRIC()
|
||||
rIC(runTasks)
|
||||
} else {
|
||||
runningRequestIdleCallback = false
|
||||
}
|
||||
|
@ -25,6 +31,7 @@ export function scheduleIdleTask (task) {
|
|||
taskQueue.push(task)
|
||||
if (!runningRequestIdleCallback) {
|
||||
runningRequestIdleCallback = true
|
||||
requestIdleCallback(runTasks)
|
||||
let rIC = getRIC()
|
||||
rIC(runTasks)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue