Long computations on Meteor

a 夏天 提交于 2020-01-11 10:35:12

问题


I learned that in Node.js you yield in between long computations to prevent the server from blocking. How do you achieve this on Meteor? Are there techniques for also doing this on the client?

I am new to web development, simple examples would be appreciated.


回答1:


Meteor uses Fibers which behave a little different than usual Node.js code. I believe there's no need to yield manually. Instead, you may want to use this.ublock() method on the server side – see this awesome article that explains it in details.

If you're doing something really heavy on the client side (like calculating Mandelbrot set), split the execution with defers:

_.defer(function() {
  doSomethingQuiteLong();
  _.defer(function() {
    doSomethingQuiteLongAgain();
    ...
  });
});



回答2:


Here is something interesting:

"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." -http://docs.meteor.com/#structuringyourapp

It seems there is no need to worry about the node.js limitation. But what does this mean then?



来源:https://stackoverflow.com/questions/22819645/long-computations-on-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!