Tag: 序列

为什么这个node.js代码不能串行执行?

我是一个总节点noob,几乎不知道我在做什么。 我试图依次执行一系列function,使用futures库。 我的代码: var futures = require('futures'); var sequence = futures.sequence(); sequence .then(function() { console.log("one"); }) .then(function() { console.log("two"); }) .then(function() { console.log("three"); }); 我希望我的输出是 one two three 但我得到的输出是 one 我究竟做错了什么?

如何依次运行多个节点stream?

给定两个stream, stream1 , stream2 ,我怎么能顺序运行它们,如果有失败,抛出? 我正在寻找比这更简单的东西: stream1.on('end',function(){ stream2.on('end',done); }); stream1.on('error',function(error){done(error);}); stream2.on('error',function(error){done(error);}); 谢谢。