简体   繁体   English

在Meteor.js中调用同步函数

[英]Calling a Synchronous function in Meteor.js

When you call a synchronous function on the Meteor server, does it block the entire server until the callback is received? 当您在Meteor服务器上调用同步函数时,它是否会阻塞整个服务器,直到收到回调为止?

queueTask = function(callback) { ... }
queueTaskSync = Meteor._wrapAsync(queueTask)
queueTaskSync(function(results) {
    console.log('callback returns after 10 seconds')
    Results.insert(results)
})

In other words, if the callback takes 10 seconds to return, does this mean the server cannot do anything else for 10 seconds? 换句话说,如果回调需要10秒钟才能返回,这是否意味着服务器在10秒钟内无法执行其他任何操作?

It depends where this code is. 这取决于此代码在哪里。 If the code is in a Meteor.methods on the server additional calls to meteor from the same client will be blocked, but other's wouldn't be blocked since they are in different fibers. 如果代码在服务器上的Meteor.methods ,则将阻止从同一客户端对流星的其他调用,但不会阻止其他流星,因为它们位于不同的光纤中。

You can bypass this using this.unblock() in your method to make sure the next method calls are run in new fibers, thus making them more concurrent-like. 您可以在方法中使用this.unblock()来绕过此this.unblock() ,以确保下一个方法调用在新的光纤中运行,从而使它们更像并发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM