在Node.js中,如何使用node-seq按顺序链接asynchronous函数?
今天我一直在玩@ substack的node-seq模块,它允许我链接在一起的asynchronousfunction。
https://github.com/substack/node-seq
我使用并行function,但顺序运行function有困难。 每当我运行下面的代码,它只打印出'hello1'语句。 任何想法我做错了什么?
var Seq = require('seq'); Seq() .seq(function () { console.log('hello1'); }) .seq(function () { console.log('hello2'); }) ;
感谢您的任何build议!
你只需要阅读文档
每个方法都会执行下一节中描述的上下文(
this
)的callback函数。 每个方法都返回this
。每当
this()
被一个非伪造的第一个参数调用时,错误值向下传播到它所看到的第一个catch
,跳过所有在它们之间的动作。 如果可用的话打印错误堆栈的所有链的末尾都有一个隐式catch
,否则只是打印错误。
this
应该可以解决你的问题。
var Seq = require('seq'); Seq() .seq(function () { console.log('hello1'); this(); }) .seq(function () { console.log('hello2'); }) ;
否则, Seq
无法知道何时完成该步骤。