diff --git a/lib/api-base.js b/lib/api-base.js index 4019d38..c2c31a8 100644 --- a/lib/api-base.js +++ b/lib/api-base.js @@ -50,7 +50,6 @@ export class BaseApplication { async _fetchResources() { // Async import, to allow inlining some of the resources within resource file. - console.log(`[YoWASP runtime] Fetching resource bundle ${this.resourceFileURL}`); const { modules, filesystem } = await import(this.resourceFileURL); return { modules: await this._fetchObject(modules, this._fetchWebAssembly), @@ -60,16 +59,19 @@ export class BaseApplication { async _fetchObject(obj, fetchFn) { // Mutate the object being fetched, to avoid re-fetches within the same session. + // Do this in parallel to avoid head-of-line blocking. + const promises = []; for (const [key, value] of Object.entries(obj)) { if (value instanceof URL) { - console.log(`[YoWASP runtime] Fetching resource file ${value}`); - obj[key] = await fetchFn(value); + promises.push(fetchFn(value).then((fetched) => [key, fetched])); } else if (typeof value === "string" || value instanceof Uint8Array) { - obj[key] = value; + promises.push(Promise.resolve([key, value])); } else { - obj[key] = await this._fetchObject(value, fetchFn); + promises.push(this._fetchObject(value, fetchFn).then((fetched) => [key, fetched])); } } + for (const [key, value] of await Promise.all(promises)) + obj[key] = value; return obj; }