-->

Meteor blocking clarification

2020-08-04 13:04发布

问题:

According to the meteor docs, inserts block:

On the server, if you don't provide a callback, then insert blocks until the database acknowledges the write, or throws an exception if something went wrong. If you do provide a callback, insert still returns the ID immediately.

So this would be wrong:

Meteor.methods({
  post: function (options) {
    return Stories.insert(options)
  }
});

I need to do this:

Meteor.methods({
  post: function (options) {
    return Stories.insert(options, function(){})
  }
});

Can somebody confirm that this is the case? The former will block the ENTIRE SERVER until the db returns?

回答1:

Yeah, it will block, but not the entire server.

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

So, if you are worried about that it will block the entire server as it will do in typical Node, don't be.