setImmediate Polyfill and Shim
JSON →The `setImmediate.js` package provides a robust, cross-browser polyfill and shim for the `setImmediate` and `clearImmediate` APIs, originally proposed by Microsoft to the Web Performance Working Group. On its current stable version 1.0.5 (last updated in 2016), it bridges the gap for efficient, non-blocking asynchronous execution, especially in older or less-spec-compliant environments. Unlike `setTimeout(..., 0)` or `process.nextTick` (in newer Node.js), `setImmediate` queues a task on the *macrotask* queue, yielding control back to the event loop before execution, allowing for rendering or I/O to occur. It differentiates itself by employing various "clever tricks" such as `postMessage`, `MessageChannel`, and historical browser-specific hacks (`<script> onreadystatechange`, `process.nextTick` in older Node) to achieve optimal performance and correct macrotask semantics across IE6+, Firefox 3+, WebKit, Opera 9.5+, and Node.js. In environments where these tricks aren't viable, it gracefully falls back to `setTimeout`, ensuring universal compatibility.
Traffic · last 30 days ↓78% vs prev 7d
top countries 🇺🇸 United States · 🇨🇦 Canada · 🇩🇪 Germany