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

Function resume_separate_thread

tests/all/component_model/async.rs:106–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104#[tokio::test]
105#[cfg_attr(miri, ignore)]
106async fn resume_separate_thread() -> Result<()> {
107 let mut config = wasmtime_test_util::component::config();
108 config.consume_fuel(true);
109 let engine = Engine::new(&config)?;
110 let component = format!(
111 r#"
112 (component
113 (import "yield" (func $yield (result (list u8))))
114 (core module $libc
115 (memory (export "memory") 1)
116 {REALLOC_AND_FREE}
117 )
118 (core instance $libc (instantiate $libc))
119
120 (core func $yield
121 (canon lower
122 (func $yield)
123 (memory $libc "memory")
124 (realloc (func $libc "realloc"))
125 )
126 )
127
128 (core module $m
129 (import "" "yield" (func $yield (param i32)))
130 (import "libc" "memory" (memory 0))
131 (func $start
132 i32.const 8
133 call $yield
134 )
135 (start $start)
136 )
137 (core instance (instantiate $m
138 (with "" (instance (export "yield" (func $yield))))
139 (with "libc" (instance $libc))
140 ))
141 )
142 "#
143 );
144 let component = Component::new(&engine, component)?;
145 let mut linker = Linker::new(&engine);
146 linker
147 .root()
148 .func_wrap_async("yield", |_: StoreContextMut<()>, _: ()| {
149 Box::new(async {
150 tokio::task::yield_now().await;
151 Ok((vec![1u8, 2u8],))
152 })
153 })?;
154
155 execute_across_threads(async move {
156 let mut store = Store::new(&engine, ());
157 store.set_fuel(u64::MAX).unwrap();
158 store.fuel_async_yield_interval(Some(1)).unwrap();
159 linker.instantiate_async(&mut store, &component).await?;
160 Ok::<_, wasmtime::Error>(())
161 })
162 .await?;
163 Ok(())

Callers

nothing calls this directly

Calls 12

yield_nowFunction · 0.85
OkFunction · 0.85
execute_across_threadsFunction · 0.85
configFunction · 0.50
newFunction · 0.50
consume_fuelMethod · 0.45
func_wrap_asyncMethod · 0.45
rootMethod · 0.45
unwrapMethod · 0.45
set_fuelMethod · 0.45
instantiate_asyncMethod · 0.45

Tested by

no test coverage detected