如何使用/ parallel

时间:2017-04-05 11:39:00

标签: javascript promise when-js

当我尝试使用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可以是一个Promises数组?但是当我尝试用这样的并行替换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);
    });

0 个答案:

没有答案