Currently, I am utilizing Vue, Node, and TypeScript for my project. One of the challenges I am facing is fetching essential data that multiple functions rely on. The getDataForFunction123()
function requires an await operation, which is working fine.
However, I have three separate functions that fetch different data independently, without being dependent on each other. The results from these functions are crucial for the final function, updateAfterFunction123IsDone()
. The issue arises when I must wait sequentially for function 1, 2, and 3 to complete before calling updateAfterFunction123IsDone()
, resulting in a significant amount of time being wasted.
I am looking for a way to modify this process so that functions 1, 2, and 3 can execute concurrently and notify me when all three are finished, allowing me to then trigger updateAfterFunction123IsDone()
.
Below is the current code snippet:
async initData () {
await this.getDataForFunction123();
await this.function1();
await this.function2();
await this.function3();
this.updateAfterFunction123IsDone();
}
I am skeptical about using Promise.all()
to address this problem as it may still execute the functions in order rather than simultaneously. Would this approach only help with error handling rather than optimizing efficiency?