Skip to content

Commit

Permalink
Priority queue: request new idle callback for each item in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 20, 2023
1 parent 33fabf5 commit 56b78d5
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/priority-queue/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,11 @@ export const createQueue = () => {
* In the case that a callback adds a new callback to its own context then
* the callback it adds will appear at the end of the iteration and will be
* run only after all other existing contexts have finished executing.
*
* @param {IdleDeadline|number} deadline Idle callback deadline object, or
* animation frame timestamp.
*/
const runWaitingList = ( deadline ) => {
for ( const [ nextElement, callback ] of waitingList ) {
waitingList.delete( nextElement );
callback();

if (
'number' === typeof deadline ||
deadline.timeRemaining() <= 0
) {
break;
}
}
const runWaitingList = () => {
const [ nextElement, callback ] = waitingList.entries().next().value;
waitingList.delete( nextElement );
callback();

if ( waitingList.size === 0 ) {
isRunning = false;
Expand Down

0 comments on commit 56b78d5

Please sign in to comment.