Created
July 30, 2019 04:22
-
-
Save jmuzsik/d689cd518cd5633f00b6fa28c7f3862a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requestIdleCallback's callback. | |
runTaskQueue(deadline) { | |
console.info(`This round of JS begins at ${this.currentTaskNumber}.`); | |
while (deadline.timeRemaining() > 0 && this.taskList.length) { | |
// deadline.timeRemaining() runs repeatedly, until it is equal | |
// to 0. It slowly decreases... 12.465 -> 11.26 -> etc. | |
const task = this.taskList.shift(); | |
this.currentTaskNumber++; | |
// This creates the DOM elements but does not log them. | |
task.handler(task.data); | |
// This adds the created elements to the DOM with requestAnimationFrame. | |
this.scheduleStatusRefresh(); | |
} | |
console.info(`And ends at ${this.currentTaskNumber}.`); | |
// Then run the next task. | |
if (this.taskList.length) { | |
this.taskHandle = requestIdleCallback(this.runTaskQueue); | |
} else { | |
this.taskHandle = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment