I have a Vue SPA that has a array of promises that are being awaited on page load.
const promiseArray = [
ServiceA.method(),
ServiceB.method(),
ServiceC.method(),
...,
ServiceZ.method()
]
Promise.allSettled(promiseArray);
As the application grows more and more complex, some of these promises/services need to complete prior to starting other calls.
For example,
ServiceA Requires ServiceD to finish
or
ServiceE requires ServiceB to finish
Is there a way to “nest” these async/await calls to keep the simplicity of a singular array and awaiting them all concurrently without introducing a large amount of complexity?
ServiceC THEN ServiceA,
ServiceF THEN ServiceD,
Is there a way to refactor to make the code behave something like this and that could possibly be extended upon to include even more dependcies in the future?
ServiceA THEN ServiceC THEN ServiceQ
ServiceB,
ServiceD
...
Currently I have the dependencies inside of the service code as there is only the one so far, but I have a couple of tickets coming in pipeline that will require more.
I will most likely end up batching these promises and run them one after another, but I was curious if there was a more elegant way.