流星阻塞澄清 [英] Meteor blocking clarification

查看:125
本文介绍了流星阻塞澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据流星文档,插入块:

在服务器上,如果你不提供一个回调,然后插入块
  直到数据库承认写,或将引发异常
  出了些问题。如果您确实提供了一个回调,仍然插
  立即返回ID。

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)
  }
});

我需要这样做:

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?

推荐答案

是的,它会阻止,但不是整个服务器。

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

在流星,你的服务器code在每个请求单个线程上运行,而不是在异步回调风格典型的节点。我们发现线性执行模型更适合在流星的应用典型的服务器code。

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.

这篇关于流星阻塞澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆