mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
chore (loader): wasm loader with cache
This commit is contained in:
parent
c1b090e210
commit
3fffac0f01
1 changed files with 20 additions and 11 deletions
|
|
@ -1,20 +1,29 @@
|
|||
const DEBUG = false;
|
||||
const log = (msg) => DEBUG && console.log(msg);
|
||||
|
||||
const wasmCache = new Map();
|
||||
|
||||
export default async function(baseURL, path, opts = {}) {
|
||||
const wasi = new Wasi();
|
||||
const wasm = await WebAssembly.instantiateStreaming(
|
||||
fetch(new URL(path, baseURL)), {
|
||||
wasi_snapshot_preview1: {
|
||||
...wasi,
|
||||
const url = new URL(path, baseURL);
|
||||
|
||||
let wasm;
|
||||
if (wasmCache.has(url.pathname)) wasm = wasmCache.get(url.pathname);
|
||||
else {
|
||||
wasm = await WebAssembly.instantiateStreaming(
|
||||
fetch(url), {
|
||||
wasi_snapshot_preview1: {
|
||||
...wasi,
|
||||
},
|
||||
env: {
|
||||
...wasi,
|
||||
...syscalls,
|
||||
...javascripts,
|
||||
},
|
||||
},
|
||||
env: {
|
||||
...wasi,
|
||||
...syscalls,
|
||||
...javascripts,
|
||||
},
|
||||
},
|
||||
);
|
||||
);
|
||||
wasmCache.set(url.pathname, wasm);
|
||||
}
|
||||
wasi.instance = wasm.instance;
|
||||
return wasm;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue