await in loop --> Promise.all()

This commit is contained in:
RMidhunSuresh 2022-07-17 22:29:36 +05:30
parent 9bdf9c500b
commit b29287c47e
2 changed files with 7 additions and 4 deletions

View file

@ -35,7 +35,7 @@ export class ThemeBuilder {
}
async populateDerivedTheme(manifest: ThemeManifest, log: ILogItem): Promise<void> {
await log.wrap("ThemeBuilder.populateThemeMap", async (l) => {
await log.wrap("ThemeBuilder.populateThemeMap", async () => {
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
const {cssLocation, derivedVariables, icons} = this._getSourceData(baseManifest, location, log);
const themeName = manifest.name;

View file

@ -60,11 +60,13 @@ export class ThemeLoader {
);
results.forEach(({ body }, i) => idToManifest.set(body.id, { manifest: body, location: manifestLocations[i] }));
this._themeBuilder = new ThemeBuilder(this._platform, idToManifest, this.preferredColorScheme);
const runtimeThemePromises: Promise<void>[] = [];
for (let i = 0; i < results.length; ++i) {
const { body } = results[i];
try {
if (body.extends) {
await this._themeBuilder.populateDerivedTheme(body, log);
const promise = this._themeBuilder.populateDerivedTheme(body, log);
runtimeThemePromises.push(promise);
}
else {
this._populateThemeMap(body, manifestLocations[i], log);
@ -74,6 +76,7 @@ export class ThemeLoader {
console.error(e);
}
}
await Promise.all(runtimeThemePromises);
Object.assign(this._themeMapping, this._themeBuilder.themeMapping);
// Add the default-theme as an additional option to the mapping
const defaultThemeId = this.getDefaultTheme();
@ -94,7 +97,7 @@ export class ThemeLoader {
}
private _populateThemeMap(manifest: ThemeManifest, manifestLocation: string, log: ILogItem) {
log.wrap("populateThemeMap", (l) => {
log.wrap("populateThemeMap", () => {
/*
After build has finished, the source section of each theme manifest
contains `built-assets` which is a mapping from the theme-id to