문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top