RAS
RAS

Reputation: 8156

Difference between queue.await() and queue.awaitAll()

I'm new to D3 & JavaScript.

I'm trying to understand queue.js in that.

I've gone through this link. But still can't get a clear cut idea about the difference between queue.await() and queue.awaitAll().

Can anyone help me with an example(if possible)?

Upvotes: 3

Views: 2144

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109252

From the documentation you've linked to:

If await is used, each result is passed as an additional separate argument; if awaitAll is used, the entire array of results is passed as the second argument to the callback.

So the difference is only in how the arguments are passed to the callback. For example

queue()
  .defer(fs.stat, __dirname + "/../Makefile")
  .defer(fs.stat, __dirname + "/../package.json")
  .await(function(error, file1, file2) { console.log(file1, file2); });

passes two additional arguments to the callback, while

queue()
  .defer(fs.stat, __dirname + "/../Makefile")
  .defer(fs.stat, __dirname + "/../package.json")
  .awaitAll(function(error, files) { console.log(files[0], files[1]); });

passes an array of results instead.

Upvotes: 5

Related Questions