-
Notifications
You must be signed in to change notification settings - Fork 109
/
index.ts
23 lines (21 loc) · 874 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export * from './mesh';
/**
* Loads the Wasm module that is provided by fetching a url.
* @param url The URL to query for the Wasm binary.
*/
export async function loadMeshStreamingWithURLAsync(url: string): Promise<void> {
return loadMeshStreamingAsync(fetch(url));
}
/**
* Loads the Wasm module that is provided by a response.
* @param response The Wasm response that supplies the Wasm binary.
*/
export async function loadMeshStreamingAsync(response: Response | Promise<Response>): Promise<void> {
const go = new Go();
const module = await WebAssembly.instantiateStreaming(response, go.importObject);
// NOTE(jalextowle): Wrapping the `go.run(module.instance)` statement in `setImmediate`
// prevents the statement from blocking when `await` is used with this load function.
setImmediate(() => {
go.run(module.instance);
});
}