Skip to content

help: Confused with 'requestIdleCallback(workLoop)' #43

@KelvinQiu802

Description

@KelvinQiu802

In Step III: Concurrent Mode, I learn that: requestIdleCallback(func) will call the call back function when the browser is idle.
But in workLoop function, that while loop confused me.

function workLoop(deadline) {
  let shouldYield = false
  while (nextUnitOfWork && !shouldYield) {
    nextUnitOfWork = performUnitOfWork(
      nextUnitOfWork
    )
    shouldYield = deadline.timeRemaining() < 1
  }
  requestIdleCallback(workLoop)
}

My question is: if shoudYield is false, it means that the browser is busy, so we should stop calling the next unit of work.
But in this while loop, if shoudYield is false, the loop will continue and do the next unit of work. Why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions