I am using async.js for my node.js app. I need help solving the following problem.
Let's say I have a following aysnc js series function.
async.waterfall([
function getDataFromDB(request, response, callback){ ... },
function someOperationOnDBData(dbData, response, callback){ ... },
function renderSomeFlow(evaluatedData, response, callback){ ... }
]);
I have three functions called in the order mentioned above. I am getting data from getDataFromDB
and passing to someOperationOnDBData
and so on.
Suppose I need one more operation in between getDataFromDB
and someOperationOnDBData
but still pass DBData forward. Eg:
async.waterfall([
function getDataFromDB(request, response, callback){ ... },
function extraOperation(dbData, response, callback) {...}
function someOperationOnDBData(dbData, extraOperationData, response, callback){ ... },
function renderSomeFlow(evaluatedData, response, callback){ ... }
]);
Here adding a single step in the middle changes the function definitions and also I need to pass dbData
in extraOperation
to just forward it to someOperationOnDBData
.
Also, if I am calling a different module in the middle, it might not be possible to change it's parameter to forward some data.
How to solve this problem of passing data between functions in async.js without forwarding data in middle functions? Refactoring functions every time a new step is included is not possible. What is the design pattern for solving this type of problem?