Stream: wasmtime

Topic: Share data from linker into wrapped functions


view this post on Zulip Ari Seyhun (Apr 07 2023 at 06:16):

Is it possible for me to share data from the context of the linker into the state of a registered function?

For example:

fn register<T>(linker: Linker<T>) -> Result<()> {
    let counter = opentelemetry::counter("some-count");
    linker.func_wrap("my::module", "register", register)?; // Register function has no way of accessing the counter?
    Ok(())
}

fn register<T>(caller: Caller<T>) {
    // I want to access the counter from here to increment it
}

I'm considering using some kind of global state for this, but was wondering if there's a better way?

view this post on Zulip Alex Crichton (Apr 07 2023 at 06:32):

That's possible, yeah, because the argument to func_wrap is a closure, but you'll probably find it more convenient to store such state within the T of the Store<T> as then you can avoid mutexes/locks/etc


Last updated: Nov 22 2024 at 16:03 UTC