Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix accidental sync call
  • Loading branch information
lewing committed Nov 16, 2021
commit 07c6f90a15805c7fc4f975c42608f7923375ac7e
9 changes: 5 additions & 4 deletions src/mono/wasm/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function _fetch_asset(url: string): Promise<Response> {
else if (ENVIRONMENT_IS_NODE) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require("fs");
Copy link
Member

@pavelsavara pavelsavara Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will do require for each call of the _fetch_asset. I admit the previous implementation had the same issue.

const arrayBuffer = await fs.readFileSync(url);
const arrayBuffer = await fs.promises.readFile(url);
return <Response><any> {
ok: true,
url,
Expand All @@ -73,15 +73,16 @@ async function _fetch_asset(url: string): Promise<Response> {
};
}
else if (typeof (read) === "function") {
const arrayBuffer = new Uint8Array(read(url, "binary"));
return <Response><any> {
ok: true,
url,
arrayBuffer: () => new Uint8Array(read(url, "binary")),
json: () => JSON.parse(read(url))
arrayBuffer: () => arrayBuffer,
json: () => JSON.parse(Module.UTF8ArrayToString(arrayBuffer, 0, arrayBuffer.length))
};
}
}
catch (e) {
catch (e: any) {
return <Response><any> {
ok: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe store the error as a property so the caller can find out what the error was without an extra throw+catch

url,
Expand Down