Skip to content

Commit

Permalink
feat: Add support for queueMicrotask (Closes #13)
Browse files Browse the repository at this point in the history
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
  • Loading branch information
Richienb authored and medikoo committed Feb 11, 2020
1 parent e3d57f8 commit 471986e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
To be used in environment agnostic modules that need nextTick functionality.

- When run in Node.js `process.nextTick` is used
- In modern browsers microtask resolution is guaranteed by `MutationObserver`
- In modern browsers, microtask resolution is guaranteed by `queueMicrotask`
- In older browsers, `MutationObserver` is used as a fallback
- In other engines `setImmediate` or `setTimeout(fn, 0)` is used as fallback.
- If none of the above is supported module resolves to `null`

Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ module.exports = (function () {
return process.nextTick;
}

// queueMicrotask
if (typeof queueMicrotask === "function") {
return function (cb) { queueMicrotask(ensureCallable(cb)) }
}

// MutationObserver
if ((typeof document === 'object') && document) {
if (typeof MutationObserver === 'function') return byObserver(MutationObserver);
Expand Down

0 comments on commit 471986e

Please sign in to comment.