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.
npm install setimmediateVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the globally available `setImmediate` for non-blocking asynchronous execution, highlighting its macrotask semantics compared to microtasks like Promises or `process.nextTick`.
Always be explicit about whether macrotask (e.g., `setImmediate`, `setTimeout`, I/O events) or microtask (e.g., Promises, `process.nextTick`) semantics are required for your asynchronous operations. If you need immediate execution within the same event loop tick, use a microtask-based solution.
Upgrade to `setimmediate@1.0.4` or newer to ensure robust and correctly asynchronous behavior across all supported browser environments.
Update to `setimmediate@1.0.3` or newer. If upgrading is not an option, avoid using string arguments with `setImmediate` (e.g., `setImmediate("myFunction()")`); instead, pass a direct function reference (e.g., `setImmediate(myFunction)`).In Node.js, ensure `require('setimmediate');` is called at the application's entry point. In browser environments, verify that the `<script>` tag loading `setimmediate.js` is correctly placed and loaded before any calls to `setImmediate`.Upgrade the `setimmediate` package to version 1.0.3 or newer. If an upgrade is not feasible, ensure that `setImmediate` is always called with a function reference, never with a string that would require `eval`.
Rethink the asynchronous flow. If an operation needs to run immediately after a Promise resolves, it should be chained with another `.then()`. If it explicitly needs to yield to the event loop for I/O or rendering before executing, `setImmediate` is correct, but be aware of its position in the task queue relative to microtasks.
No dependency data recorded yet.