Skip to content

Commit

Permalink
Improved init function to play better with Cloudflare Workers
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Dec 7, 2021
1 parent f6e4544 commit 6647bb7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import load, { WASI } from "./pkg/index";
export * from "./pkg/wasmer_wasi_js";
import { InitInput } from "./pkg/wasmer_wasi_js";
import load from "./pkg/wasmer_wasi_js";
import wasm_bytes from "./pkg/wasmer_wasi_js_bg.wasm";

Expand Down Expand Up @@ -71,15 +72,12 @@ function dataUriToBuffer(uri: string): MimeBuffer {
}

let inited: Promise<any> | null = null;
export const init = async () => {
if (inited === null) {
inited = load(await WebAssembly.compile(dataUriToBuffer(wasm_bytes as any as string)));
export const init = async (input?: InitInput | Promise<InitInput>, force?: boolean) => {
if (inited === null || force === true) {
if (!input) {
input = await WebAssembly.compile(dataUriToBuffer(wasm_bytes as any as string));
}
inited = load(input);
}
await inited;
}
// console.log(wasm_bytes)
// export class WASI extends WASIDefault {

// }
// // pkg.init()
// let wasi = new WASI({}, null)

0 comments on commit 6647bb7

Please sign in to comment.