jeudi 10 janvier 2019

Is it a good idea to chain multiple service calls in Angular 7

I am creating a basic MEAN app and while working on it, I have to call multiple services one after the another. For example, while placing an order:

PlaceOrder(){
   productService.CheckAvailability().subscribe(() => {
       if (available){
          customerService.GetCustomer().subscribe(() =>{
             if(newCustomer){
                   customerService.CreateCustomer().subscribe(() => {
                         orderService.CreateOrder().subscribe(() => {
                                console.log("Order placed");
                          });
                    });
              }
              else //old customer
               {
                     orderService.CreateOrder().subscribe(() => {
                              console.log("order placed");
                      });
                }
          });
       } //endif
   });
}

Now, I am wondering if it is a good idea and application design to chain these service calls this way Or if this design is going to impact the application speed and efficiency. The same goes with Nodejs server also. There, I have sequential db updates.

Aucun commentaire:

Enregistrer un commentaire