瀑布为什么这么慢?
我正在为 Node 使用异步模块(请参阅 https://github.com/caolan/async)。我的问题是...为什么瀑布这么慢?
执行这段代码大约需要4秒...
App.post("/form", function(request, response) {
Async.waterfall([
function(callback) {
console.log("1.");
callback(null, "some data");
},
function(data, callback) {
console.log("2.");
callback(null, "some data");
},
function(data, callback) {
console.log("3.");
callback(null, "some data");
}
], function(error, document) {
console.log("4.");
console.log("Done.");
response.send(); // Takes 4 seconds
});
}
输出
1.
2.
// After 4 seconds
3.
4.
Done.
谢谢回复!
I'm using async module (see https://github.com/caolan/async) for Node.js and my question is... Why is waterfall so slow?
It takes about 4 seconds to execute this piece of code...
App.post("/form", function(request, response) {
Async.waterfall([
function(callback) {
console.log("1.");
callback(null, "some data");
},
function(data, callback) {
console.log("2.");
callback(null, "some data");
},
function(data, callback) {
console.log("3.");
callback(null, "some data");
}
], function(error, document) {
console.log("4.");
console.log("Done.");
response.send(); // Takes 4 seconds
});
}
Output
1.
2.
// After 4 seconds
3.
4.
Done.
Thanks for reply!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是另一个 Node.js 错误。
在待处理的
http.ServerResponse
期间,在另一个process.nextTick
中使用process.nextTick
会被破坏。这需要很长时间,
async.js
从其他回调内部调用回调,这些回调是通过process.nextTick
调用的,然后导致触发上述错误。快速修复:在
async.js
行63
中修改async.nextTick
以仅使用setTimeout.
错误:我已就此提交了问题 。
It's just another Node.js Bug.
Using
process.nextTick
inside anotherprocess.nextTick
during a pendinghttp.ServerResponse
is broken.This takes an eternity,
async.js
calls the callbacks from inside the other callbacks which were called viaprocess.nextTick
which then results in the above bug being triggered.Quick fix: In
async.js
line63
modifiyasync.nextTick
to only usesetTimeout
.Bug: I've filed an issue on this.