3

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)?

RAS
  • 8,100
  • 16
  • 64
  • 86

1 Answers1

5

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.

Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
  • This array of results contain files or json objects in the files? – RAS Dec 31 '13 at 12:31
  • The result depends on the call. For the examples, it's file stats, i.e. size etc. – Lars Kotthoff Dec 31 '13 at 14:43
  • Can you please give me some more specification about it? Can you add code for file1 & file2 & how can I access them in both the methods? – RAS Jan 07 '14 at 06:43
  • You can't access the files. This example *stats* the files, i.e. you get a data structure that gives you information about the files. You access those data structures as illustrated in the `console.log` code. – Lars Kotthoff Jan 07 '14 at 06:45
  • Ok I'll try it & get back to you. – RAS Jan 07 '14 at 06:48