import * as Runno from '@runno/wasi' import { patchImportObject } from './patch-wasi' /** @typedef {{ * stdin: (len: number) => Uint8Array | null, * stdout: (out: Uint8Array) => void, * stderr: (err: Uint8Array) => void, * }} MyStdioDef */ /** @typedef {Partial< * Omit & MyStdioDef * >} PatchedRunnoWASIContextOptions */ /** @param {PatchedRunnoWASIContextOptions} opt * @returns {Runno.WASIContextOptions} */ function definePatchedRunnoWASIContextOptions(opt) { return /** @type {Runno.WASIContextOptions} */( /** @type {unknown} */ (opt)) } const wasi = new WASI(definePatchedRunnoWASIContextOptions({ stdout(buf) { console.log(buf.byteLength) } /* ... */ }) const importObject = patchImportObject(wasi, timeout => { // let waitDuration = timeout < 0 ? Infinity : Math.max(timeout - Date.now(), 0) // return stdinReader.pollRead(waitDuration) }) const wasm = await WebAssembly.instantiateStreaming(fetch('...'), importObject)