meteor/meteor — pull request #953 by awwx (2013-04-16 00:43:11+00:00)
Title: Allow a setImmediate polyfill to be used by Meteor.defer

Meteor code commonly uses `setTimeout(f, 0)` to defer execution, but browsers will delay calling the callback for longer than the requested timeout period. (Most browsers enforce a minimum timeout, some expand the minimum to one second in inactive tabs, and iOS doesn't call a setTimeout callback in inactive tabs at all).

Sometimes this is what you want (if, for example, you have some code that you don't want to run often in inactive tabs). But it can be unexpectedly weird if several setTimeout 0's are used in a row and it turns into multi-second delays.

This PR allows a smart package to inject a setImmediate polyfill (such as [this implementation](https://github.com/NobleJS/setImmediate#readme)), which will be used by `Meteor.defer`.

By default, on the server process.nextTick is used, and on the client setImmediate is used if available; otherwise falls back to setTimeout.