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

为什么这个node.js代码不串联执行?,node.js,sequence,Node.js,Sequence,我是个彻头彻尾的傻瓜,几乎不知道自己在做什么。我正在尝试使用futures库按顺序一个接一个地执行一系列函数。我的代码: var futures = require('futures'); var sequence = futures.sequence(); sequence .then(function() { console.log("one"); }) .then(function() { console.log("two"); }) .then(fu

我是个彻头彻尾的傻瓜,几乎不知道自己在做什么。我正在尝试使用
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

我做错了什么

Node.js正在处理回调函数,所以您需要匿名传递它,以使futures执行下一个函数:

var futures = require('futures');
var sequence = futures.sequence();

sequence
  .then(function(next) {
    console.log("one");
    next(null, 1);
  })
  .then(function(next) {
    console.log("two");
    next(null, 2);
  })
  .then(function(next) {
    console.log("three");
    next(null, 3);
  });

期货
在不断变化。为什么不使用更健壮、更流行的模块
async
。它有你可能需要的所有这些操作

您所追求的是
async.series


我首先尝试使用async,它也有同样的问题
async.series([
    function(callback){
        // do some stuff ...
        callback(null, 'one');
    },
    function(callback){
        // do some more stuff ...
        callback(null, 'two');
    }
],
// optional callback
function(err, results){
    // results is now equal to ['one', 'two']
});