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

Function recursive_call

tests/all/async_functions.rs:142–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140#[tokio::test]
141#[cfg_attr(miri, ignore)]
142async fn recursive_call() {
143 let mut store = async_store();
144 let func_ty = FuncType::new(store.engine(), None, None);
145 let async_wasm_func = Func::new_async(&mut store, func_ty, |_caller, _params, _results| {
146 Box::new(async {
147 tokio::task::yield_now().await;
148 Ok(())
149 })
150 });
151
152 // Create an imported function which recursively invokes another wasm
153 // function asynchronously, although this one is just our own host function
154 // which suffices for this test.
155 let func_ty = FuncType::new(store.engine(), None, None);
156 let func2 = Func::new_async(&mut store, func_ty, move |mut caller, _params, _results| {
157 Box::new(async move {
158 async_wasm_func
159 .call_async(&mut caller, &[], &mut [])
160 .await?;
161 Ok(())
162 })
163 });
164
165 // Create an instance which calls an async import twice.
166 let module = Module::new(
167 store.engine(),
168 "
169 (module
170 (import \"\" \"\" (func))
171 (func (export \"\")
172 ;; call imported function which recursively does an async
173 ;; call
174 call 0
175 ;; do it again, and our various pointers all better align
176 call 0))
177 ",
178 )
179 .unwrap();
180
181 let instance = Instance::new_async(&mut store, &module, &[func2.into()])
182 .await
183 .unwrap();
184 let func = instance.get_func(&mut store, "").unwrap();
185 func.call_async(&mut store, &[], &mut []).await.unwrap();
186}
187
188#[tokio::test]
189#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 8

yield_nowFunction · 0.85
OkFunction · 0.85
async_storeFunction · 0.70
newFunction · 0.50
engineMethod · 0.45
call_asyncMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45

Tested by

no test coverage detected