I want to write in Node.JS the equivalent of the following synchronous code:
function(param)
{
if(condition1(param)) {f(param);}
else if(condition2(param)){g(param);}
else if(condition3(param)){h(param);}
...
}
Where the verification of the conditions is possibly doing some database, filesystem or even http I/O; so should not be run in such a synchronous code.
Simple but dirty solution: one can chain callbacks as in the answer to that question How to write a non-blocking if statement in Node JS?
But when the number of conditions are high it becomes easily unreadable and hard to modify (eg. to change the order of the conditions).
Is there a nice pattern that can be used to keep such a code neat?