Skip to content

Call js promise-functions from C wasm, with callbacks instead of asyncify/etc.

Notifications You must be signed in to change notification settings

easywasm/promises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This will let you call js promise-functions from C wasm, with callbacks instead of asyncify/etc.

Essentially, you pick a host implementation, and a wasm-implementation for your language, and they will allow callbacks, and it's able to respond.

host

JS (node/browser/etc)

import { wrapPromise, callPromise } from "@easywasm/promises";

const imports = {
  env: {
    // here is a promise-returning function that the wasm will get the output of
    example_host_func: wrapPromise((messageP) => new Promise((resolve) => setTimeout(() => resolve('nice!'), 1000)))
  },
};

const wasmBytes = "...";
const mod = await WebAssembly.compile(wasmBytes);
const instance = await WebAssembly.instantiate(mod, imports);

// wait for getting the response back
const response = await callPromise(instance.exports, instance.exports.test);

wasm

C

For a C example, that can perform http-requests and process it, see:

I am faking http, but you can see the result is the output of mycallback

About

Call js promise-functions from C wasm, with callbacks instead of asyncify/etc.

Resources

Stars

Watchers

Forks

Packages

No packages published