Using the Q library with node.js,
I'd like to create a simple flow with 5-6 steps for each request and I'm trying to decide between two options of passing a request id to each step of the flow.
function(){
var reqId = generateId();
// opt a
firstStep(reqId)
.then(secondStep);
}
function firstStep(reqId){
var resultOfFirstStep = doSomething();
promise.resolve({
reqId: reqId,
result: resultOfFirstStep
});
}
function secondStep(data){
var reqId = data.reqId
...
}
// opt b
function(){
var reqId = generateId();
firstStep(reqId)
.then(secondStep.bind(this,reqId));
}
function firstStep(reqId){
var resultOfFirstStep = doSomething();
promise.resolve(result);
}
function secondStep(reqId,result){
...
}
The first option doesn't seem very elegant, whereas I'm not sure whether it is advisable to create a copy of each function due to the usage of bind().
Or maybe I'm missing a better way of achieving this?
Thanks.