I have a piece of code which runs 4 async
functions:
this.groupsLevels = await this.groupsLevelsService.getData();
this.indicators = await this.configurationService.getIndicators();
this.sources = await this.configurationService.getSources();
this.storeGroups = await this.storeGroupsService.getStoreGroups();
console.log(this.groupsLevels) // All of them is populated
console.log(this.indicators) // All of them is populated
console.log(this.sources) // All of them is populated
console.log(this.storeGroups) // All of them is populated
How Can I run all of 4 in parallel ? and get the final result when all of them is done.?
I tried
Promise.all([
async () => {this.groupsLevels = await this.groupsLevelsService.getData(); },
async () => {this.indicators = await this.configurationService.getIndicators(); },
async () => {this.sources = await this.configurationService.getSources(); },
async () => {this.storeGroups = await this.storeGroupsService.getStoreGroups(); },
]);
console.log(this.groupsLevels)
console.log(this.indicators)
console.log(this.sources)
console.log(this.storeGroups)
But no one was loaded successfully.
what am I doing wrong?