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

邮差的信 提交于 2019-12-14 01:23:40

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/20853275/difference-between-queue-await-and-queue-awaitall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!