1

I understand that node.js has a lot of functions that runs async, like the I/O functions. I am trying to run two modules that I created in a async way, these modules only use the CPU, not an I/O request.

For example, I have something like this: I call f2() first, but I want it so if f1() ends first it won't wait until f2() has finished; is that possible? This is only an example, but I will use this calling another js file.

I tried to write this using the process.nextTick(), but I don't know if that's the real solution.

function f1(){

    for (i=0;i< 100;i++){

    }
    console.log("f1")
}

function f2(){

    for (i=0;i< 100000000000;i++){

    }
    console.log("f2")
}


f2();
f1();

1 Answer 1

1

There is an async module for doing just this

look at the parallel example in the following post node.js async libs

async.parallel([
    function(){ ... },
    function(){ ... }
], callback);

the wiki for async.js https://github.com/caolan/async

Sign up to request clarification or add additional context in comments.

1 Comment

this wait until the first func ends why? async.parallel([ function (callback) { var i = 0; for (i;i< 100000000;i++){ } callback(null, i); }, function (callback) { var i = 0; for (i;i< 100;i++){ } callback(null, i); } ], function (err, data) { if (err) throw err; console.log(data); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.