in order to avoid long loading screens ( I have these issues in my backend code as well which need to be refactored ), parts of the code need to run async.
what does you mean? don't I already have async code using promises?
every time you use .then you create a synchronous chain. that means that you have to first find all the crusts, then you have to find all the toppings, then you have to find all the meats, etc..
okay, how can I run all of those database queries all at once?
Using Promise.all to first find all matching toppings in the database with proper mongodb query objects in an array and then once they all return their promise, going through all the returned objects and adding them to the order which gets returned in the response object.
in order to avoid long loading screens ( I have these issues in my backend code as well which need to be refactored ), parts of the code need to run async.
Using
Promise.all
to first find all matching toppings in the database with proper mongodb query objects in an array and then once they all return their promise, going through all the returned objects and adding them to the order which gets returned in the response object.using bluebird - npm using native promise - mdn