Skip to content

Commit

Permalink
feat: add queueMicrotask implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 17, 2023
1 parent a16834f commit 45d1784
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/queueMicrotask.ts
@@ -0,0 +1,13 @@
import setImmediate from './setImmediate';

type TQueueMicroTask = (callback: () => void) => void;

let promise: Promise<void>

const _queueMicrotask: TQueueMicroTask = typeof queueMicrotask === 'function'
? queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
: cb => (promise ||= Promise.resolve())
.then(cb)
.catch(err => setImmediate(() => { throw err }))

export default _queueMicrotask;

0 comments on commit 45d1784

Please sign in to comment.