Skip to content

Commit

Permalink
Inline queueMicrotask polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jan 26, 2021
1 parent cd43d12 commit 41eeb82
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/scheduler/src/queueMicrotask.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
*
*/

function queueMicrotaskPolyfill(callback: boolean => void) {
if (typeof queueMicrotask !== 'undefined') {
queueMicrotask(callback);
} else if (typeof Promise !== 'undefined') {
Promise.resolve(null)
.then(callback)
.catch(e => {
setTimeout(() => {
throw e;
});
});
} else {
setTimeout(callback);
}
}
const queueMicrotaskImpl =
typeof queueMicrotask === 'function'
? queueMicrotask
: typeof Promise !== 'undefined'
? callback =>
Promise.resolve(null)
.then(callback)
.catch(e => {
setTimeout(() => {
throw e;
});
})
: setTimeout;

export default queueMicrotaskPolyfill;
export default queueMicrotaskImpl;

0 comments on commit 41eeb82

Please sign in to comment.