File tree Expand file tree Collapse file tree 4 files changed +38
-12
lines changed
wasmtime/src/runtime/component
examples/resource-component Expand file tree Collapse file tree 4 files changed +38
-12
lines changed Original file line number Diff line number Diff line change @@ -290,9 +290,22 @@ impl Func {
290
290
store. 0 . async_support( ) ,
291
291
"cannot use `call_async` without enabling async support in the config"
292
292
) ;
293
- store
294
- . on_fiber ( |store| self . call_impl ( store, params, results) )
295
- . await ?
293
+ #[ cfg( feature = "component-model-async" ) ]
294
+ {
295
+ let future = self . call_concurrent ( store. as_context_mut ( ) , params. to_vec ( ) ) ;
296
+ let run_results = self . instance . run ( store, future) . await ??;
297
+ assert_eq ! ( run_results. len( ) , results. len( ) ) ;
298
+ for ( result, slot) in run_results. into_iter ( ) . zip ( results) {
299
+ * slot = result;
300
+ }
301
+ Ok ( ( ) )
302
+ }
303
+ #[ cfg( not( feature = "component-model-async" ) ) ]
304
+ {
305
+ store
306
+ . on_fiber ( |store| self . call_impl ( store, params, results) )
307
+ . await ?
308
+ }
296
309
}
297
310
298
311
#[ cfg( feature = "component-model-async" ) ]
Original file line number Diff line number Diff line change @@ -180,15 +180,28 @@ where
180
180
& self ,
181
181
mut store : impl AsContextMut < Data : Send > ,
182
182
params : Params ,
183
- ) -> Result < Return > {
183
+ ) -> Result < Return >
184
+ where
185
+ Params : ' static ,
186
+ Return : ' static ,
187
+ {
184
188
let mut store = store. as_context_mut ( ) ;
185
189
assert ! (
186
190
store. 0 . async_support( ) ,
187
191
"cannot use `call_async` when async support is not enabled on the config"
188
192
) ;
189
- store
190
- . on_fiber ( |store| self . call_impl ( store, params) )
191
- . await ?
193
+ #[ cfg( feature = "component-model-async" ) ]
194
+ {
195
+ let prepared = self . prepare_call ( store. as_context_mut ( ) , params) ?;
196
+ let call = concurrent:: queue_call ( store. as_context_mut ( ) , prepared) ?;
197
+ self . func . instance . run ( store, call) . await ?
198
+ }
199
+ #[ cfg( not( feature = "component-model-async" ) ) ]
200
+ {
201
+ store
202
+ . on_fiber ( |store| self . call_impl ( store, params) )
203
+ . await ?
204
+ }
192
205
}
193
206
194
207
/// Start a concurrent call to this function.
Original file line number Diff line number Diff line change @@ -2745,10 +2745,10 @@ impl<'a> InterfaceGenerator<'a> {
2745
2745
func. item_name( ) . to_snake_case( ) ,
2746
2746
) ;
2747
2747
2748
- let param_mode = if let CallStyle :: Concurrent = & style {
2749
- TypeMode :: Owned
2750
- } else {
2748
+ let param_mode = if let CallStyle :: Sync = & style {
2751
2749
TypeMode :: AllBorrowed ( "'_" )
2750
+ } else {
2751
+ TypeMode :: Owned
2752
2752
} ;
2753
2753
2754
2754
for ( i, param) in func. params . iter ( ) . enumerate ( ) {
Original file line number Diff line number Diff line change @@ -138,11 +138,11 @@ async fn main() -> Result<()> {
138
138
let component = Component :: from_file ( & engine, "target/wasm32-wasip2/debug/guest_kvdb.wasm" ) ?;
139
139
let bindings = KvDatabase :: instantiate_async ( & mut store, & component, & linker) . await ?;
140
140
let result = bindings
141
- . call_replace_value ( & mut store, "hello" , "world" )
141
+ . call_replace_value ( & mut store, "hello" . to_string ( ) , "world" . to_string ( ) )
142
142
. await ?;
143
143
assert_eq ! ( result, None ) ;
144
144
let result = bindings
145
- . call_replace_value ( & mut store, "hello" , "wasmtime" )
145
+ . call_replace_value ( & mut store, "hello" . to_string ( ) , "wasmtime" . to_string ( ) )
146
146
. await ?;
147
147
assert_eq ! ( result, Some ( "world" . to_string( ) ) ) ;
148
148
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments