MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / initialize

Method initialize

crates/wizer/src/wasmtime.rs:55–86  ·  view source on GitHub ↗

Instantiate the module and call its initialization function.

(
        &self,
        store: &mut Store<T>,
        instance: &wasmtime::Instance,
    )

Source from the content-addressed store, hash-verified

53
54 /// Instantiate the module and call its initialization function.
55 async fn initialize<T: Send>(
56 &self,
57 store: &mut Store<T>,
58 instance: &wasmtime::Instance,
59 ) -> wasmtime::Result<()> {
60 log::debug!("Calling the initialization function");
61
62 if let Some(export) = instance.get_export(&mut *store, "_initialize") {
63 if let Extern::Func(func) = export {
64 func.typed::<(), ()>(&store)?
65 .call_async(&mut *store, ())
66 .await
67 .context("calling the Reactor initialization function")?;
68
69 if self.get_init_func() == "_initialize" {
70 // Don't run `_initialize` twice if the it was explicitly
71 // requested as the init function.
72 return Ok(());
73 }
74 }
75 }
76
77 let init_func = instance
78 .get_typed_func::<(), ()>(&mut *store, self.get_init_func())
79 .expect("checked by `validate_init_func`");
80 init_func
81 .call_async(&mut *store, ())
82 .await
83 .with_context(|| format!("the `{}` function trapped", self.get_init_func()))?;
84
85 Ok(())
86 }
87}
88
89/// Implementation of [`InstanceState`] backed by Wasmtime.

Callers 1

runMethod · 0.45

Calls 7

OkFunction · 0.85
get_init_funcMethod · 0.80
with_contextMethod · 0.80
get_exportMethod · 0.45
contextMethod · 0.45
call_asyncMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected