From 03ba63e108281231a8bda851941b3dca6e29b510 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Sun, 18 Jul 2021 00:26:11 +0200 Subject: [PATCH] docs: Document the WASM streaming APIs. (#11430) --- docs/getting_started/webassembly.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/getting_started/webassembly.md b/docs/getting_started/webassembly.md index 0285c3b9a1..307aba452b 100644 --- a/docs/getting_started/webassembly.md +++ b/docs/getting_started/webassembly.md @@ -21,7 +21,7 @@ const main = wasmInstance.exports.main as CallableFunction console.log(main().toString()); ``` -And for files: +For files: ```ts const wasmCode = await Deno.readFile("main.wasm"); @@ -30,3 +30,14 @@ const wasmInstance = new WebAssembly.Instance(wasmModule); const main = wasmInstance.exports.main as CallableFunction; console.log(main().toString()); ``` + +And for loading WebAssembly modules over the network (note that the file must be +served with `application/wasm` MIME type): + +```ts +const { instance, module } = await WebAssembly.instantiateStreaming( + fetch("https://wpt.live/wasm/incrementer.wasm"), +); +const increment = instance.exports.increment as (input: number) => number; +console.log(increment(41)); +```