问题
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