Skip to content

Commit

Permalink
Eliminate extra Promise when using scheduler.yield()
Browse files Browse the repository at this point in the history
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
  • Loading branch information
westonruter and swissspidy committed Oct 10, 2024
1 parent 8538799 commit 70077b8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/interactivity/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ const afterNextFrame = ( callback: () => void ) => {
* @return Promise
*/
export const splitTask = () => {
if (
'scheduler' in window &&
typeof window.scheduler === 'object' &&
null !== window.scheduler &&
'yield' in window.scheduler &&
typeof window.scheduler.yield === 'function'
) {
return window.scheduler.yield();
}
return new Promise( async ( resolve ) => {
if (
'scheduler' in window &&
typeof window.scheduler === 'object' &&
null !== window.scheduler &&
'yield' in window.scheduler &&
typeof window.scheduler.yield === 'function'
) {
await window.scheduler.yield();
resolve( undefined );
} else {
setTimeout( resolve, 0 );
}
setTimeout( resolve, 0 );
} );
};

Expand Down

0 comments on commit 70077b8

Please sign in to comment.