0

I'm a bit stumped at what I might be doing wrong when I'm trying to use the when.js parallel function:

https://github.com/cujojs/when/blob/master/docs/api.md#whenparallel

var parallel = require('when/parallel');

var resultsPromise = parallel(arrayOfTasks, arg1, arg2 /*, ... */);

As far as I understand arrayOfTasks can be an array of Promises? But I run into the error "TypeError: task.apply is not a function" when I try to replace a when.all with parallel like this:

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);
    });
Community
  • 1
  • 1
blub
  • 8,757
  • 4
  • 27
  • 38
  • 1
    `arrayOfTasks` suggests **functions** ... a *Promise* (which is what you've got an array of) is **not** a *function* - from the documentation `each may return a promise or a value` - so the *function* can return a promise or a value, but `arrayOfTasks` **must** be an array of *functions* – Jaromanda X Apr 05 '17 at 11:42
  • @JaromandaX That doesn't seem right... E.g. here is a gist by the creator that seems to be using Promises: https://gist.github.com/briancavalier/5948810 – blub Apr 05 '17 at 11:59
  • Ah, no, I missed the wrapper function in the gist, so you're right. It seems silly that I have to wrap the promises in functions, but oh well. If you answer the question I can set you answer as accepted. – blub Apr 05 '17 at 12:39

0 Answers0