Skip to content

Instantly share code, notes, and snippets.

@pomber
Last active October 13, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pomber/5619519b8fce0174d839419fd44ccf04 to your computer and use it in GitHub Desktop.
Save pomber/5619519b8fce0174d839419fd44ccf04 to your computer and use it in GitHub Desktop.
const ENOUGH_TIME = 1; // milliseconds
function performWork(deadline) {
workLoop(deadline);
if (nextUnitOfWork || updateQueue.length > 0) {
requestIdleCallback(performWork);
}
}
function workLoop(deadline) {
if (!nextUnitOfWork) {
resetNextUnitOfWork();
}
while (nextUnitOfWork && deadline.timeRemaining() > ENOUGH_TIME) {
nextUnitOfWork = performUnitOfWork(nextUnitOfWork);
}
if (pendingCommit) {
commitAllWork(pendingCommit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment