mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 16:32:31 +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 DEBUG = false;
|
||||||
const log = (msg) => DEBUG && console.log(msg);
|
const log = (msg) => DEBUG && console.log(msg);
|
||||||
|
|
||||||
|
const wasmCache = new Map();
|
||||||
|
|
||||||
export default async function(baseURL, path, opts = {}) {
|
export default async function(baseURL, path, opts = {}) {
|
||||||
const wasi = new Wasi();
|
const wasi = new Wasi();
|
||||||
const wasm = await WebAssembly.instantiateStreaming(
|
const url = new URL(path, baseURL);
|
||||||
fetch(new URL(path, baseURL)), {
|
|
||||||
wasi_snapshot_preview1: {
|
let wasm;
|
||||||
...wasi,
|
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,
|
wasmCache.set(url.pathname, wasm);
|
||||||
...syscalls,
|
}
|
||||||
...javascripts,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
wasi.instance = wasm.instance;
|
wasi.instance = wasm.instance;
|
||||||
return wasm;
|
return wasm;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue