Skip to content Skip to sidebar Skip to footer

In Node.js, How Do I Chain Asynchronous Functions Sequentially Using Node-seq?

Today I have been playing with @substack's node-seq module, it allows me to chain together async functions. https://github.com/substack/node-seq I got it working with parallel fun

Solution 1:

You just need to read the documentation

Each method executes callbacks with a context (its this) described in the next section. Every method returns this.

Whenever this() is called with a non-falsy first argument, the error value propagates down to the first catch it sees, skipping over all actions in between. There is an implicit catch at the end of all chains that prints the error stack if available and otherwise just prints the error.

this should solve your problem.

var Seq = require('seq');

Seq()
    .seq(function () {
        console.log('hello1');
        this();
    })
    .seq(function () {
        console.log('hello2');
    })
;

Otherwise Seq has no way of knowing when the step is done.

Post a Comment for "In Node.js, How Do I Chain Asynchronous Functions Sequentially Using Node-seq?"