Questions tagged [async.js]

A module with functions for working asynchronously with JavaScript that can be used both in NodeJS and in the browser.

Async is a utility module which provides straight-forward, powerful functions for working with . Although originally designed for use with , it can also be used directly in the browser.

Resources

944 questions
66
votes
9 answers

Iterating over a mongodb cursor serially (waiting for callbacks before moving to next document)

Using mongoskin, I can do a query like this, which will return a cursor: myCollection.find({}, function(err, resultCursor) { resultCursor.each(function(err, result) { } } However, I'd like to call some async functions for each…
UpTheCreek
  • 28,433
  • 31
  • 143
  • 214
25
votes
2 answers

Node + Sequelize: How to check if item exists before adding? (async confusion)

I am unfortunately new to node and running into some confusion regarding the asynchronous/synchronous execution of node. I am using node, sequelize with sqlite and async.js. I have a series of Articles, each of which has a number of Authors. For…
waffl
  • 4,140
  • 5
  • 60
  • 108
17
votes
2 answers

Node.js - Async.js: how does parallel execution work?

I want to know how parallel execution works in async.js async = require('async') async.parallel([ function(callback){ for (var i = 0; i < 1000000000; i++) /* Do nothing */; console.log("function: 1") }, …
15
votes
5 answers

Async.js - Is parallel really parallel?

As I have understood so far: Javascript is single threaded. If you defer the execution of some procedure, you just schedule it (queue it) to be run next time the thread is free. But Async.js defines two methods: Async::parallel &…
14
votes
3 answers

Error handling with Node.js, Async and Formidable

In the following snippet I would like to validate the fields in the first async method. If they are not valid I would like to return an error to the user immediately. How do I do that? var form = new formidable.IncomingForm(); async1.series([ …
Robben_Ford_Fan_boy
  • 7,544
  • 7
  • 55
  • 80
13
votes
2 answers

async.eachSeries in node.js

I have a loop in node.js for (var i in files){ var all = fs.readdirsync("./0"); async.eachSeries(all, function(item){ check(item); } } The check(item) has a callback to another function. As I can see, the async.eachSeries…
Or Smith
  • 3,178
  • 12
  • 33
  • 60
13
votes
3 answers

Pass extra argument to async map

Signature for async.map is map(arr, iterator, callback) (https://github.com/caolan/async#map) I have a var context //object and I need to pass this to the iterator. How do i do this ?
user644745
  • 5,313
  • 9
  • 47
  • 78
11
votes
1 answer

Async each vs forEach js

Can someone explain me the different between this two: async.each(items, function (item, callback) { // Do something }); OR : items.forEach(function(item) { // Do something )};
Avihay m
  • 481
  • 1
  • 4
  • 17
11
votes
3 answers

What is the difference between async.map or async.each with async.parallel?

I started working on a node project recently and have been using the async library a lot. I'm kind of confused as to which option will be faster. Using async.map on some data and getting its results or using async.each to iterate over an array of…
Mukul Raina
  • 241
  • 4
  • 13
11
votes
4 answers

node.js async series function's arguments

I need to do the code like following: function taskFirst(k, v) { console.log(k, v); } function taskSecond(k, v) { console.log(k, v); } function run() { var g1 = "Something"; var g2 = "Something"; var g3 = "Something"; var…
Dmitry
  • 191
  • 2
  • 11
11
votes
4 answers

Is there a way to stop execution of next function of series with async in nodejs?

async.map(list, function(object, callback) { async.series([ function(callback) { console.log("1"); var booltest = false; // assuming some logic is performed that may or may not change booltest …
Rolando
  • 44,077
  • 84
  • 230
  • 353
10
votes
1 answer

Async queue, filestream end how to know when both finished

I am having a slight issue when using async.queue with a filestream I have a scenario where my filestream will finish I set fileRead to true however the queue will be empty and already have called drain this then leads my "done" to never be…
user2950720
  • 932
  • 2
  • 8
  • 21
9
votes
2 answers

Multiple paginated GET API calls in parallel/async in Node

I am making call to the bitbucket API to get all the files that are in a repo. I have reached to a point where I can get the list of all the folders in the repo and make the first API call to all the root folders in the repo in parallel and get the…
Grinish Nepal
  • 2,927
  • 2
  • 23
  • 45
9
votes
1 answer

node.js async.js nextTick vs setImmediate

I have a large node.js application that heavily uses the async.js module. I have a lot of code like this: async.series([ function(callback){ sql.update(query, callback); }, function(callback){ if (something){ …
Christie
  • 161
  • 2
  • 7
9
votes
1 answer

NodeJS, Async forEachSeries execution order

Just trying to get my head around using Async module for NodeJS. I have the following code. var a1 = [1,2,3,4,5,6,7,8]; async.forEachSeries(a1, function(n1, callback) { console.log(n1); var a2 = [10,11,12,13,14]; async.forEachSeries(a2,…
ericbae
  • 9,378
  • 22
  • 73
  • 103
1
2 3
62 63