Questions tagged [node-async]

Async is a utility module for node.js (although it can also be used in the browser) that provides powerful functions for working with asynchronous JavaScript

Async provides around 20 functions that include the usual 'functional' suspects (map, reduce, filter, each...) as well as some common patterns for asynchronous control flow (parallel, series, waterfall...).

All these functions assume you follow the convention of providing a single callback as the last argument of your async function.


Documentation :

185 questions
119
votes
4 answers

What is the difference between async.waterfall and async.series

The nodejs async module: https://github.com/caolan/async provides 2 similar methods, async.waterfall and async.series. What is the difference between them?
Bruce Dou
  • 4,673
  • 10
  • 37
  • 56
53
votes
2 answers

Node.js - Using the async lib - async.foreach with object

I am using the node async lib - https://github.com/caolan/async#forEach and would like to iterate through an object and print out its index key. Once complete I would like execute a callback. Here is what I have so far but the 'iterating done' is…
Ben
  • 6,026
  • 11
  • 51
  • 72
37
votes
6 answers

async.js each get index in iterator

I'm using caolan's async.js library, specifically the .each method. How do you get access to the index in the iterator? async.each(ary, function(element, callback){ //do stuff here for each element in ary //how do I get access to the index? },…
Kevin
  • 3,441
  • 6
  • 34
  • 40
11
votes
1 answer

Determining success/failure with node.js function async.retry

I'm studying the node.js module async, but I have some problems with the function async.retry. According to its github docs, the function will continue trying the task until it succeeds or chances are used up. But how can my task tell success or…
Yao Zhao
  • 4,373
  • 4
  • 22
  • 30
10
votes
1 answer

Async waterfall passing in arguments

I have a question regarding passing arguments in async.waterfall() to the third function rather than the first function. For example, as following async.waterfall([ first, second, async.apply(third, obj) ], function(err, result){}); Now is…
RRP
  • 2,563
  • 6
  • 29
  • 52
10
votes
2 answers

Will async.parallel still call the final callback after all tasks are done if any of them gets error?

var async = require('async'); async.parallel([ function(cb) { cb(true); }, function(cb) { cb(null, true); }], function(error, results) { } ); In the code, if the first task runs cb(true) before the second tasks, will the second…
Joe C
  • 2,757
  • 2
  • 26
  • 46
10
votes
2 answers

node.js: program either exits unexpectedly or just hangs

I wrote a module in node.js that performs some network operation. I wrote a small script that uses this module (the variable check below). It looks like this: check(obj, function (err, results) { // ... console.log("Check…
Aishwar
  • 9,284
  • 10
  • 59
  • 80
8
votes
3 answers

Node.js/Async - How to avoid callback hell with async?

I'm new to Node.Js and JavaScript web development on the backend. I see that callbacks inside callbacks could be a pain and there are modules to avoid that. One of these modules is async, https://github.com/caolan/async I've read the documentation…
André
  • 24,706
  • 43
  • 121
  • 178
8
votes
1 answer

node.js async.series not working

This piece of code was taken straight out of the example from: https://github.com/caolan/async#seriestasks-callback var async = require("async"); async.series([ function() { console.log("a"); }, function() { console.log("b"); } ],…
Soyeed
  • 263
  • 1
  • 5
  • 12
7
votes
2 answers

The "err" argument when using Async waterfall in node.js

I am trying to execute a series of functions, each passing the callback to the next. Right now it looks like this (excuse any minor errors, I am rewriting it as I post!): function func1(callback) { callback(null, "stuff"); } function…
V_H
  • 1,793
  • 3
  • 34
  • 59
6
votes
3 answers

Why calling next() in express routes is optional?

In many examples of Nodejs/Express, I see that calling next() is optional in case of success. exports.postLogin = (req, res, next) => { passport.authenticate("local", (err, user, info) => { if (err) { return next(err); } …
ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
6
votes
1 answer

Node js + multiple nested inner functions with callback

I have nested inner functions with callback that are with in the single function(abcd). I need to call abcd function from outside using async and return the response. var listFunctions = { test1 : function(objectData, callbackData) { …
RSKMR
  • 1,812
  • 5
  • 32
  • 73
6
votes
1 answer

async and Q promises in nodejs

I'm using the Q library and async library in nodejs. Here's an example of my code: async.each(items, cb, function(item) { saveItem.then(function(doc) { cb(); }); }, function() { }); saveItem is a promise. When I run this, I always get cb…
dzm
  • 22,844
  • 47
  • 146
  • 226
6
votes
2 answers

Node.JS async.parallel doesn't wait until all the tasks have completed

I am using aync.parallel to run two functions in parallel. The functions request RSS feeds. Then the RSS feeds are parsed and added to my web page. But for some reason async.parallel runs the callback method without waiting until the two functions…
6
votes
1 answer

Reduced nesting with async.waterfall but added clutter

I am trying to reduce the nesting of async calls (node + socket.io) by using async.waterfall and I ended up having to append parameters down the waterfall because they are needed later. This code might explain better: // Original version: socket…
wtjones
  • 4,090
  • 4
  • 34
  • 41
1
2 3
12 13