Skip to content

Commit

Permalink
Await the next animation frame between core data API calls in __exper…
Browse files Browse the repository at this point in the history
…imentalBatch()
  • Loading branch information
adamziel committed Aug 25, 2021
1 parent 29b6a5a commit 7d861e0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,16 @@ export function* __experimentalBatch( requests ) {
);
},
};
const resultPromises = requests.map( ( request ) => request( api ) );
const resultPromises = [];
const awaitNextFrame = () => __unstableAwaitPromise( new Promise( window.requestAnimationFrame ) );
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.
yield awaitNextFrame();
}
const [ , ...results ] = yield __unstableAwaitPromise(
Promise.all( [ batch.run(), ...resultPromises ] )
);
Expand Down

0 comments on commit 7d861e0

Please sign in to comment.