New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async.parallel is not working if I don't use setTimeout #4
Comments
remember that you only have a single thread of execution, so without using setTimeout the pause() function will block. Using async.parallel will not make your javascript asynchronous, rather it will help you properly manage asynchronous operations. If you need to run javascript like this in parallel you'll need to use multiple processes or look into web workers. |
I tried setTimeout for pause case also. But it didn't work. function task(name, delay, callback, useTimeout){ |
I'll look into web workers. Thanks for quick response. |
I have following simple program. I am looking to parallelize this program using web-worker. function process(delay){ var start = new Date(); var start = new Date(); |
Hi,
I have following code. This is working as expected if I use setTimeOout. If I simulate delay instead of using setTimeout, parallization is not working.
var async = require('async');
function getTasks(useTimeout){
return [
function(callback){
task("task 1", 500, callback, useTimeout)
}
,
function(callback){
task("task 2", 400, callback, useTimeout)
}
];
}
function task(name, delay, callback, useTimeout){
if(useTimeout){
console.log(name + "(" + delay +")");
setTimeout(function(){
callback(null, name);
},delay);
}else{
console.log(name + "(" + pause(delay) +")");
callback(null, name);
}
}
function callback(err, results){
console.log("async.parallel : "+ (new Date()-start) + "\n");
}
function pause(delay){
var start = new Date();
var len = 300000*delay;
for(var i=0;i<len;i++){};
return (new Date()-start);
}
var start = new Date();
//async.parallel(getTasks(false),callback);
async.parallel(getTasks(true),callback);
The text was updated successfully, but these errors were encountered: