queue-microtask
fast, tiny `queueMicrotask` shim for modern engines
When you write JavaScript, sometimes you need to schedule a small piece of code to run "very soon" — not immediately, but right after the current task finishes, before the browser or server moves on to other work. The modern standard way to do this is a built-in function called queueMicrotask. The queue-microtask package lets developers use this function safely across all modern JavaScript environments, even older versions of Node.js and browsers that don't support it natively yet.
Under the hood, if the JavaScript engine already supports queueMicrotask, the package just uses it directly. If it doesn't, the package falls back to using Promise.resolve().then(fn), which achieves the same effect with the same performance. The entire implementation is under ten lines of code with zero dependencies, so it adds almost no weight to your project.
This package is for developers building JavaScript applications who want to keep their bundle size as small as possible while still supporting a wide range of environments. For example, if you're building a library that runs in both the browser and Node.js and you need to defer a quick task — like flushing a batch of updates — without the heavy delays of setTimeout, this package handles the inconsistency across platforms for you. If you only need to support Node 12 and later, you don't need this package at all; you can use the built-in function directly.
What stands out about this project is its extreme minimalism and the deliberate tradeoff it makes. Other libraries that solve similar problems exist and support very old browsers, but they come with extra code and larger file sizes. This package intentionally skips support for ancient environments lacking Promise support, choosing instead to stay as tiny as possible while delivering optimal performance for the vast majority of users on modern engines.