-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
27 lines (21 loc) · 888 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export const wasmBrowserInstantiate = async (wasmModuleURL, importObject) => {
let response;
// dont have support for streaming instantiation
if ( !WebAssembly.instantiateStreaming ) {
// download its entire module then instantiate it
const fetchAndInstantiateTask = async () => {
const wasmArrayBuffer = await fetch(wasmModuleURL)
.then(response => response.arrayBuffer());
return WebAssembly.instantiate(wasmArrayBuffer, importObject);
}
response = await fetchAndInstantiateTask();
return response;
}
// fetch the wasm module via streaming and instantiate it as it is downloading
response = await WebAssembly.instantiateStreaming(
fetch(wasmModuleURL),
importObject
);
return response;
}
export const go = new Go(); // defined in wasm_exec