@@ -2314,9 +2314,6 @@ impl Instance {
23142314 /// #
23152315 /// # async fn foo() -> Result<()> {
23162316 /// # let mut config = Config::new();
2317- /// # config.wasm_component_model(true);
2318- /// # config.wasm_component_model_async(true);
2319- /// # config.async_support(true);
23202317 /// # let engine = Engine::new(&config)?;
23212318 /// # let mut store = Store::new(&engine, ());
23222319 /// # let mut linker = Linker::new(&engine);
@@ -2336,7 +2333,7 @@ impl Instance {
23362333 /// // let (future,) = call.await?;
23372334 ///
23382335 /// // OK, since we use `Instance::run` to poll `call` inside the event loop:
2339- /// let (future,) = instance.run(&mut store, call).await?;
2336+ /// let (future,) = instance.run(&mut store, call).await?? ;
23402337 ///
23412338 /// let future = future.into_reader(&mut store);
23422339 ///
@@ -2386,28 +2383,72 @@ impl Instance {
23862383 /// futures passed to `run`.
23872384 ///
23882385 /// ```
2386+ /// # use {
2387+ /// # anyhow::Result,
2388+ /// # wasmtime::{
2389+ /// # component::{ Component, Linker, Resource, ResourceTable },
2390+ /// # Config, Engine, Store
2391+ /// # },
2392+ /// # };
2393+ /// #
2394+ /// # struct MyResource(u32);
2395+ /// # struct Ctx { table: ResourceTable }
2396+ /// #
2397+ /// # async fn foo() -> Result<()> {
2398+ /// # let mut config = Config::new();
2399+ /// # let engine = Engine::new(&config)?;
2400+ /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() });
2401+ /// # let mut linker = Linker::new(&engine);
2402+ /// # let component = Component::new(&engine, "")?;
2403+ /// # let instance = linker.instantiate_async(&mut store, &component).await?;
2404+ /// # let foo = instance.get_typed_func::<(Resource<MyResource>,), (Resource<MyResource>,)>(&mut store, "foo")?;
2405+ /// # let bar = instance.get_typed_func::<(u32,), ()>(&mut store, "bar")?;
23892406 /// let resource = store.data_mut().table.push(MyResource(42))?;
23902407 /// let call = foo.call_concurrent(&mut store, (resource,));
2391- /// let (another_resource,) = instance.run(&mut store, call).await?;
2408+ /// let (another_resource,) = instance.run(&mut store, call).await?? ;
23922409 /// let value = store.data_mut().table.delete(another_resource)?;
23932410 /// let call = bar.call_concurrent(&mut store, (value.0,));
2394- /// instance.run(&mut store, call).await?;
2411+ /// instance.run(&mut store, call).await??;
2412+ /// # Ok(())
2413+ /// # }
23952414 /// ```
23962415 ///
23972416 /// - Call `run_with` once and use `Accessor::with` to access the store from
23982417 /// within the future.
23992418 ///
24002419 /// ```
2401- /// instance.run_with(&mut store, Box::pin(|accessor| async move {
2402- /// let another_resource = accessor.with(|store| {
2403- /// let resource = store.data_mut().table.push(MyResource(42))?;
2404- /// Ok(foo.call_concurrent(store, (resource,)))
2420+ /// # use {
2421+ /// # anyhow::{Result, Error},
2422+ /// # wasmtime::{
2423+ /// # component::{ Component, Linker, Resource, ResourceTable, Accessor, Access },
2424+ /// # Config, Engine, Store
2425+ /// # },
2426+ /// # };
2427+ /// #
2428+ /// # struct MyResource(u32);
2429+ /// # struct Ctx { table: ResourceTable }
2430+ /// #
2431+ /// # async fn foo() -> Result<()> {
2432+ /// # let mut config = Config::new();
2433+ /// # let engine = Engine::new(&config)?;
2434+ /// # let mut store = Store::new(&engine, Ctx { table: ResourceTable::new() });
2435+ /// # let mut linker = Linker::new(&engine);
2436+ /// # let component = Component::new(&engine, "")?;
2437+ /// # let instance = linker.instantiate_async(&mut store, &component).await?;
2438+ /// # let foo = instance.get_typed_func::<(Resource<MyResource>,), (Resource<MyResource>,)>(&mut store, "foo")?;
2439+ /// # let bar = instance.get_typed_func::<(u32,), ()>(&mut store, "bar")?;
2440+ /// instance.run_with(&mut store, move |accessor: &mut Accessor<_, _>| Box::pin(async move {
2441+ /// let (another_resource,) = accessor.with(|mut access: Access<Ctx, Ctx>| {
2442+ /// let resource = access.table.push(MyResource(42))?;
2443+ /// Ok::<_, Error>(foo.call_concurrent(access, (resource,)))
24052444 /// })?.await?;
2406- /// accessor.with(|store | {
2407- /// let value = store.data_mut() .table.delete(another_resource)?;
2408- /// Ok(bar.call_concurrent(store , (value.0,)))
2445+ /// accessor.with(|mut access: Access<Ctx, Ctx> | {
2446+ /// let value = access .table.delete(another_resource)?;
2447+ /// Ok::<_, Error> (bar.call_concurrent(access , (value.0,)))
24092448 /// })?.await
2410- /// })).await?;
2449+ /// })).await??;
2450+ /// # Ok(())
2451+ /// # }
24112452 /// ```
24122453 pub async fn run_with < U : Send , V : Send + Sync + ' static , F > (
24132454 & self ,
0 commit comments