问题
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