0

I am developing a simple farming game backend using meteor.

So Server needs to check all players farm data and based on that for example increment

production:0

field each second if player has a farm. What is the best way to do that ?

Should i use Meteor.setTimeout()

l0veisreal
  • 179
  • 5
  • 20

1 Answers1

1

You should use Meteor.setTimeout if you don't manually want to bind fibers to the callback function.

Related issues:

What's going on with Meteor and Fibers/bindEnvironment()?

Meteor wrapAsync or bindEnvironment without standard callback signature

However, you can also use the native JS setTimeout but you will have to manually bind a fiber to the callback (if you aim to use for example Mongo) using Meteor.bindEnvironment or Meteor.wrapAsync.

Another interesting tool is Meteor.defer which is similar to Meteor.setTimeout(func, 0) and allows to execute code in the background. Beware of several layers of callbacks when mixing with Meteor.setTimeout.

Ans yet another tool when executing complex services in a method is this.unblock.

Applying these tools in an appropriate way will make your timer based update possible.

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59