Closed codeuniquely closed 9 years ago
wait.parallel.launch expects an array of [[fn,arg,arg..],[fn,arg,arg..],...] and then launches a fiber for each function call, in parallel and waits for all the fibers to complete. The functions should be sync/normal functions and the calls are made without adding any parameters
in wait.parallel.launch(arr) The functions to be called _should not be async functions_. Each called function will be executed in a fiber, and this sync called function should/can use wait.for internally in order to call async functions.
It seems that you're assuming the functions to be called should be async and that's not the case for wait.parallel.launch. it's this way because the same parallel.launch is used to implement parallel.map and parallel.test, and for those cases, a normal non-async mapping/test function is the most common use-case
Here's fixed:
var wait=require('./waitfor');
function fdone(p1,p2){
console.log(p1,p2);
}
function func1(req, done) {
console.log(req);
console.log(done);
done(null, 'write some code for 1');
}
function func2(req, done) {
console.log(req);
console.log(done);
done(null, 'write some code for 2');
}
function test() {
var arrFunc = [];
arrFunc.push([func1, "hi 1", fdone]); // all func1 required parameters
arrFunc.push([func2, "hi 2", fdone]); // all func2 required parameters
var data = wait.parallel.launch(arrFunc);
console.log(data);
}
wait.launchFiber(test);
Just a suggestion but maybe it would be a good idea to put that in the documentation as an example on how to use those functions
It's a good idea. I've already added more detail in the README for wait.parallel.launch Maybe you have a better example of a real-use case of wait.parallel.launch? In a real use case, the called functions should use wait.for internally (no real "parallelism" if they not) and it should not be a case best covered by wait.parallel.map|filter
it may just be that I'm not calling it right but
I was expecting to get some output in data and then log it but what I actually get is
It seems that the callback ('done' in this case) is not being passed in and the callback fails. The same happens with any request that I could normally pass into a wait.for() call.