Instantiate the module and call its initialization function.
(
&self,
store: &mut Store<T>,
instance: &wasmtime::Instance,
)
| 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. |
no test coverage detected