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

Method module_async

crates/wasmtime/src/runtime/linker.rs:867–928  ·  view source on GitHub ↗
(
        &mut self,
        mut store: impl AsContextMut<Data = T>,
        module_name: &str,
        module: &Module,
    )

Source from the content-addressed store, hash-verified

865 /// details on Wasmtime's out-of-memory handling.
866 #[cfg(feature = "async")]
867 pub async fn module_async(
868 &mut self,
869 mut store: impl AsContextMut<Data = T>,
870 module_name: &str,
871 module: &Module,
872 ) -> Result<&mut Self>
873 where
874 T: Send + 'static,
875 {
876 // NB: this is intended to function the same as `Linker::module`, they
877 // should be kept in sync.
878 assert!(
879 Engine::same(&self.engine, store.as_context().engine()),
880 "different engines for this linker and the store provided"
881 );
882 match ModuleKind::categorize(module)? {
883 ModuleKind::Command => self.command(
884 store,
885 module_name,
886 module,
887 |store, func_ty, export_name, instance_pre| {
888 let upvars = Arc::new((instance_pre, export_name));
889 Func::new_async(
890 store,
891 func_ty.clone(),
892 move |mut caller, params, results| {
893 let upvars = upvars.clone();
894 Box::new(async move {
895 let (instance_pre, export_name) = &*upvars;
896 let instance = instance_pre.instantiate_async(&mut caller).await?;
897
898 instance
899 .get_export(&mut caller, &export_name)
900 .unwrap()
901 .into_func()
902 .unwrap()
903 .call_async(&mut caller, params, results)
904 .await?;
905 Ok(())
906 })
907 },
908 )
909 },
910 ),
911 ModuleKind::Reactor => {
912 let instance = self.instantiate_async(&mut store, &module).await?;
913
914 if let Some(export) = instance.get_export(&mut store, "_initialize") {
915 if let Extern::Func(func) = export {
916 let func = func
917 .typed::<(), ()>(&store)
918 .context("loading the Reactor initialization function")?;
919 func.call_async(&mut store, ())
920 .await
921 .context("calling the Reactor initialization function")?;
922 }
923 }
924

Callers 5

instantiate_and_runMethod · 0.80
linker_module_commandFunction · 0.80
linker_module_reactorFunction · 0.80
mainFunction · 0.80
linker_module_asyncFunction · 0.80

Calls 11

OkFunction · 0.85
commandMethod · 0.80
newFunction · 0.50
cloneMethod · 0.45
instantiate_asyncMethod · 0.45
call_asyncMethod · 0.45
unwrapMethod · 0.45
into_funcMethod · 0.45
get_exportMethod · 0.45
contextMethod · 0.45
instanceMethod · 0.45

Tested by 1

linker_module_asyncFunction · 0.64