Chained functions with callbacks while maintaining separation of concerns
In the codebase I took, we have an asynchronous method chaining that expands to two modules with different functional goals.
ie we do some things with GeneralTravel
and then pass the data into Hotel
related things:
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 is with this code flow (other than being torture to follow),
- I want to decide from
Travel
whatHotel
should be done with its data -
Hotel.makeCall
doesn't even know what its callback is!//see 1 & 2 in code
While this code design might fit well in other cases, I think we need improvement here.
Is this the organization of the modules? naming? chain of calls?
PS: in a world without async! What's up?:)
+3
source to share
No one has answered this question yet
See similar questions:
or similar: