Skip to content

Instantly share code, notes, and snippets.

@mit-mit
Last active May 15, 2024 10:48
Show Gist options
  • Save mit-mit/0fcb1247a9444b0cadf611aa5fc6f32e to your computer and use it in GitHub Desktop.
Save mit-mit/0fcb1247a9444b0cadf611aa5fc6f32e to your computer and use it in GitHub Desktop.
Dart web Wasm bootstrap
(async function () {
let dart2wasm_runtime;
let moduleInstance;
try {
const dartModulePromise = WebAssembly.compileStreaming(fetch('main.wasm'));
const imports = {};
dart2wasm_runtime = await import('./main.mjs');
moduleInstance = await dart2wasm_runtime.instantiate(dartModulePromise, imports);
} catch (exception) {
console.error(`Failed to fetch and instantiate wasm module: ${exception}`);
console.error('See https://dart.dev/web/wasm for more information.');
}
if (moduleInstance) {
try {
await dart2wasm_runtime.invoke(moduleInstance);
} catch (exception) {
console.error(`Exception while invoking test: ${exception}`);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment