Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async scheduling of batched updates #34295

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,17 @@ export function* __experimentalBatch( requests ) {
);
},
};
const resultPromises = requests.map( ( request ) => request( api ) );
const resultPromises = [];
const awaitNextFrame = () =>
__unstableAwaitPromise( new Promise( window.requestAnimationFrame ) );
adamziel marked this conversation as resolved.
Show resolved Hide resolved
for ( const request of requests ) {
resultPromises.push( request( api ) );

// Each request( api ) is pretty fast, but when there's a lot of them it may block the browser for a few
// seconds. Let's split this long, blocking task into bite-sized pieces scheduled separately to give the
// browser a space for processing other tasks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify more what request calls are doing here? Can you share examples? I have trouble understanding why this would be blocking the UI.

yield awaitNextFrame();
}
const [ , ...results ] = yield __unstableAwaitPromise(
Promise.all( [ batch.run(), ...resultPromises ] )
);
Expand Down