Meteor.defer
over Meteor.setTimeout
JS-0729Meteor.setTimeout
can be used to defer the execution of a function, but Meteor has a built-in method for deferring called Meteor.defer
. It is better to use the dedicated method instead of relying on a side-effect of Meteor.setTimeout
.
Using Meteor.defer
is preferred because it uses native setImmediate
or postMessage
methods if available. Otherwise, it can fall back to setTimeout
. Also, setTimeout
adds a delay of at least 2ms in Chrome, 10ms in other browsers, which results in performance issues.
Meteor.setTimeout(function () {}, 0)
Meteor.setTimeout(function () {})
Meteor["setTimeout"](function () {}, 0)
Meteor.setTimeout(city, 0)
Meteor.setTimeout(city)
Meteor["setTimeout"](city, 0)
Meteor.defer(function () {}, 0)
Meteor.setTimeout(function () {}, 100)
Meteor.defer(city, 0)
Meteor.setTimeout(city, 100)