@polywrap/asyncify-js
TypeScript icon, indicating that this package has built-in type declarations

0.12.2 • Public • Published

@polywrap/asyncify-js

A 0 dependency wrapper around the Node.JS & Browser WebAssembly instance, which adds support for asyncify, enabling the use of async host import functions.

Usage

import { AsyncWasmInstance } from "@polywrap/asyncify-js";

// module.wasm must be asyncify enabled
const module: ArrayBuffer = getModule("./module.wasm");
const memory = new WebAssembly.Memory({ initial: 1 });

const instance = await AsyncWasmInstance.createInstance({
  module,
  imports: {
    my: {
      custom_import: async (arg: number): Promise<number> => {
        return await someAsyncCall(arg);
      }
    },
    env: {
      memory
    }
  }
});

await instance.exports.main();

Readme

Keywords

none

Package Sidebar

Install

npm i @polywrap/asyncify-js

Weekly Downloads

50

Version

0.12.2

License

MIT

Unpacked Size

42 kB

Total Files

22

Last publish

Collaborators

  • polywrap-build-bot
  • dorgjelli