npm install immediate --save
var immediate = ;;;
immediate takes the tricks from setImmedate and RSVP and combines them with the schedualer inspired (vaugly) by whens.
Several new features were added in versions 3.1.0 and 3.2.0 to maintain parity with process.nextTick, but the 3.0.x series is still being kept up to date if you just need the small barebones version
Note that we check for actual Node.js environments, not emulated ones like those produced by browserify or similar.
postMessage has completely different semantics inside web workers, and so cannot be used there. So we
MessageChannel, which has worse browser support, but does work inside a web worker.
For our last trick, we pull something out to make things fast in Internet Explorer versions 6 through 8: namely,
<script> element and firing our calls in its
onreadystatechange event. This does execute in a future
turn of the event loop, and is also faster than
setTimeout(…, 0), so hey, why not?
We avoid this process.nextTick in node is better suited to our needs and in Internet Explorer 10 there is a broken version of setImmediate we avoid using this.