Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Meteor blocking clarification

Meteor blocking clarification

Problem

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?

Problem courtesy of: Harry

Solution

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.

Solution courtesy of: Aaron Wang

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Meteor blocking clarification

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×