First analogue php - function sleep in js:
function sleep(seconds) {
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + seconds*1000);
}
Then my example :
var async = require('async');
var a = function(callback)
{
sleep(10)
console.log("Hello ");
callback(null,'vals1')
// return 'prop'
};
var b = function(callback)
{
//I want get return 'prop' from a() its posible ?
sleep(30)
console.log("World");
callback(null,"vals2")
};
var c = function(callback)
{
//I want get return 'prop' from a() its posible ?
sleep(2)
console.log(" and U");
callback(null,"val3")
};
async.parallel(
[
a,b,c
],function(err,vals){
//console.log(err)//undefined
console.log(vals) //[val1,vals2]
console.log('finals')
}
);
series(tasks, [callback])
Run the functions in the tasks array in series, each one running once the previous function has completed. If any functions in the series pass an error to its callback, no more functions are run, and callback is immediately called with the value of the error. Otherwise, callback receives an array of results when tasks have completed.
parallel(tasks, [callback])
Run the tasks array of functions in parallel, without waiting until the previous function has completed. If any of the functions pass an error to its callback, the main callback is immediately called with the value of the error. Once the tasks have completed, the results are passed to the final callback as an array.
My result :
break about 10sec
Hello
break about 30sec
World
and small break
and U
I expected to perform the functions in the following order :
output immediately
and U
break about 10sec
Hello
break about 30sec
World
If even replace your example on
async.series()
the result will be the same