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()
|
const taskQueue = new Queue()
|
||||||
let runningRequestIdleCallback = false
|
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) {
|
function runTasks (deadline) {
|
||||||
mark('scheduleIdleTask:runTasks()')
|
mark('scheduleIdleTask:runTasks()')
|
||||||
while (taskQueue.length && deadline.timeRemaining() > 0) {
|
while (taskQueue.length && deadline.timeRemaining() > 0) {
|
||||||
taskQueue.shift()()
|
taskQueue.shift()()
|
||||||
}
|
}
|
||||||
if (taskQueue.length) {
|
if (taskQueue.length) {
|
||||||
requestIdleCallback(runTasks)
|
let rIC = getRIC()
|
||||||
|
rIC(runTasks)
|
||||||
} else {
|
} else {
|
||||||
runningRequestIdleCallback = false
|
runningRequestIdleCallback = false
|
||||||
}
|
}
|
||||||
|
@ -25,6 +31,7 @@ export function scheduleIdleTask (task) {
|
||||||
taskQueue.push(task)
|
taskQueue.push(task)
|
||||||
if (!runningRequestIdleCallback) {
|
if (!runningRequestIdleCallback) {
|
||||||
runningRequestIdleCallback = true
|
runningRequestIdleCallback = true
|
||||||
requestIdleCallback(runTasks)
|
let rIC = getRIC()
|
||||||
|
rIC(runTasks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue