In Meteor, why would one use Meteor.setTimeout() over just normal setTimeout()?
What is the value of using Meteor.setTimeout() instead of just the vanilla setTimeout or setInterval?
On the client, there's no difference between them.
On the server, when code is running for a specific user (for example in method calls), you need to use Meteor.setTimeout
instead of window.setTimeout
to make Meteor remember for which user the function should be called. In the time between the function passed to Meteor.setTimeout
is called and when it's called, other users may have called methods on the server, chancing Meteor.userId
to return their user id instead. Meteor.setTimeout
will change back so Meteor.userId
return the user id for the user the call to Meteor.setTimeout
was made before calling the function passed to it.
It is a design decision.
Using Meteor.setTimeout()
ensures that this code is Fibers aware. Read more about Fibers: https://github.com/laverdet/node-fibers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With