当我尝试使用 when.js 并行函数时,我对可能做错的事情感到有些困惑:
https://github.com/cujojs/when/blob/master/docs/api.md#whenparallel
var parallel = require('when/parallel');
var resultsPromise = parallel(arrayOfTasks, arg1, arg2 /*, ... */);
据我了解,arrayOfTasks 可以是一个 Promise 数组?但是当我尝试用这样的并行替换 when.all 时遇到错误“TypeError:task.apply 不是函数”:
var when = require('when');
var parallel = require('when/parallel');
var arrayOfPromises = [
when.resolve('a'),
when.resolve('b'),
when.resolve('c'),
];
return parallel(arrayOfPromises)
.then(function(parseResultArray) {
console.log("result", parseResultArray);
});