Call function with context remotely in Node.js

I am trying to write a javascript program which executes series of functions sequentially (say function1, function2 ... function5). I want the execution of these functions to continue irrespective of the success or failure of the previous functions, i.e. function1 returns success, function2 returns success, function3 returns error (but the execution does not stop here), function4 returns success and functio5 returns success.

Now when one of the functions returns error, I want to retry execution of that function separately. In the above example, I want to try to re-execute function3 (the input and output of function3 are independent of other functions). But I want the module where functions 1-5 are running different from the module which does the re-execution. So I need a way to execute functions in on module through another module. So I have two questions now,

1. Is there an error handing library in javascript to do this?

2. If not, how do I pass the context/state of the documents/objects in one module to a function in the different module (say, error recovery module) for re-execution ?
PS: I am relatively new to javascript, hence I do not know if any pattern exists to deal with such scenario. In Java, I assume, you would serialize the object, spawn a different thread, use RMI to send the context and re-execute the function remotely.

Thank you.

There are a lot of different approaches here, depending on the details.

As for the error retrying, just pass the function to a module like attempt. Or make it a promise-based pattern so on the failed promise, retry the current function.

Other stuff, depends on your details.

Do you want to pass the same argument to all of the functions? It looks like it, since you want to retry step number 3 regardless of others. You can simply use async.

function first() {
    // do stuff
    return 1;
}
function second() {
    // do stuff
    return 2;
}
// ... up to fifth

async.series([first, second, third, fourth, fifth], function (err, results) {
    console.log('Results: ', results); // should return [1, 2, 3, 4, 5] 
});

Or maybe you want a waterfall, pass results of the previous function to the next? Then you'd use something like async-waterfall.

Do you want to store success or not? Globally? Locally? What about number of retries?

This is the best I can do without further info.