Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about import host async fn... #2857

Closed
rsta79 opened this issue Apr 23, 2022 · 2 comments
Closed

Question about import host async fn... #2857

rsta79 opened this issue Apr 23, 2022 · 2 comments
Labels
❓ question I've a question!

Comments

@rsta79
Copy link

rsta79 commented Apr 23, 2022

Summary

How can I import a host async function like exmaples?
(maybe not 100% correct, some code I wrote in github Issue)

Additional details

/host/src/main.rs

async fn my_async_fn() {
    do_something().await;
}

fn main() {
    let wasm = fs::read("../wasm32-unknown-unknown/debug/guest.wasm").unwrap();
    let store = Store::default();
    let module = Module::new(&store, wasm).unwrap();
    let instance = Instance::new(&module,&imports! {
        "async" => {
            "my_async_fn" => my_async_fn
        }
    }).unwrap();
    let func: NativeFunc<(), ()> = instance.exports.get_native_function("guest_fn").unwrap();
    func.call();
}

/guest/src/lib.rs

// this crate will be compile as wasm32-unknown-unknown

#[link(wasm_import_module = "async")]
extern "C" {
    async fn my_async_fn();
}

#[no_mangle]
extern async fn guest_fn() {
    my_async_fn().await;
}
@rsta79 rsta79 added the ❓ question I've a question! label Apr 23, 2022
@heyjdp
Copy link

heyjdp commented Apr 27, 2022

This requires async support in Wasmer, this is planned for Wasmer 3.x

@heyjdp
Copy link

heyjdp commented Apr 27, 2022

Work ongoing here: #1127

@heyjdp heyjdp closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question I've a question!
Projects
None yet
Development

No branches or pull requests

2 participants