In the codebase I picked up, we have a chain of async methods that expands to two modules with different functional purposes.
i.e we do some stuff with GeneralTravel
and then pass on the data to Hotel
related stuff:
Travel.processRequest(req){
//... then
processHotel(req, Hotel.makeCall);
}
Travel.processHotel(.., callback){
//...
callback(null, Hotel.fillDB); // 1 calls MakeCall
}
Hotel.makeCall(err, callback){
//...
callback(); // 2
}
Hotel.fillDB(){
//...
return;
}
My problem with this code flow is (apart from the fact that it's a torture to follow),
- I donT want to decide from within
Travel
, whatHotel
should do with its data Hotel.makeCall
doesn't even know what its callback is!//see 1 & 2 in code
While in other cases this code design might fit well, i think we need an improvement here.
Is it the organization of modules? naming? the call chain?
PS: in a world without async! how was life? :)