From 6647bb77ed19684049a4235b7c90d3c5874677a5 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 7 Dec 2021 14:03:49 +0100 Subject: [PATCH] Improved init function to play better with Cloudflare Workers --- lib.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib.ts b/lib.ts index bb0c6f05..492c998a 100644 --- a/lib.ts +++ b/lib.ts @@ -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"; @@ -71,15 +72,12 @@ function dataUriToBuffer(uri: string): MimeBuffer { } let inited: Promise | 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, 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)