question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version of async.series where each task receives the results of all previous tasks

See original GitHub issue

I frequently encounter a situation where a async.series task need the results of several previous tasks. async.waterfall is insufficient since it only provides the result of the last previous task. async,auto is too verbose, and provides additional, unneeded dependency declaration.

A new function (or an improvment of async.series) would come in handy. Each task would receive a result object containing the results of all previous tasks

Possible names: accumulate, seriesAccumulate

Example:

async.accumulate({
    one: function(callback){
        setTimeout(function(){
            callback(null, 1);
        }, 200);
    },
    two: function(callback, results){
        // results: {one: 1}
        setTimeout(function(){
            callback(null, 2);
        }, 100);
    },
    three: function(callback, results){
         // results: {one: 1, two: 2}
        setTimeout(function(){
            callback(null, results.one + results.two);
        }, 100);
    }
},
function(err, results) {
    // results is now equal to: {one: 1, two: 2, three: 3}
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
aearlycommented, Mar 22, 2016

Closing this. I don’t think we need another method between series and waterfall in style.

1reaction
alexpuschcommented, Nov 16, 2015

As I mentioned, in a simple series scenario async.auto is too verbose, The user have to declare that each step is dependent on the previous one, resulting in those ugly arrays and duplicate step names

async.auto({
    one: function(callback){
        setTimeout(function(){
            callback(null, 1);
        }, 200);
    },
    two: ["one", function(callback, results){
        setTimeout(function(){
            callback(null, 2);
        }, 100);
    }],
    three: ["two", function(callback, results){
        setTimeout(function(){
            callback(null, results.one + results.two);
        }, 100);
    }
   ]
},
function(err, results) {
    // results is now equal to: {one: 1, two: 2, three: 3}
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Callback not getting called while using async.series
Async gives every single task a callback which you need to call to let async now that this task finished. After all tasks...
Read more >
Understanding Node.js Async Flows: Parallel, Serial, Waterfall ...
Callback : This is the callback where all the task results are passed and executed once all the task execution has completed. The...
Read more >
Clean Code NodeJs : Execute Asynchronous Tasks in Series
When all the tasks complete the execution, then the final callback will be called and return the results to the server.
Read more >
Asynchronous flow control using async - MDN Web Docs
The method async.series() is used to run multiple asynchronous operations in sequence, when subsequent functions do not depend on the output of ...
Read more >
Understanding Asynchronous Programming in Node.js | InformIT
The Async module has a method called series() that allows us to control the execution flow of callbacks. The series() method takes an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found