use anyhow::Context; use bytes::Bytes; use futures::{stream, StreamExt as _}; use tokio::join; use tracing::info; #[allow(dead_code)] pub async fn assert_async( client: &impl wrpc_transport::Invoke, ) -> anyhow::Result<()> { wit_bindgen_wrpc::generate!({ world: "async-client", path: "tests/wit", }); info!("calling `wrpc-test:integration/async.with-streams`"); let ((a, b), io) = wrpc_test::integration::async_::with_streams(client, C::default()) .await .context("failed to call `wrpc-test:integration/async.with-streams`")?; join!( async { info!("receiving `a`"); assert_eq!(a.collect::>().await.concat(), b"test"); }, async { info!("receiving `b`"); assert_eq!( b.collect::>().await.concat(), [["foo"].as_slice(), ["bar", "baz"].as_slice()] ); }, async { if let Some(io) = io { info!("performing I/O"); io.await.expect("failed to complete async I/O"); } } ); info!("calling `wrpc-test:integration/async.with-future`"); let (fut, io) = wrpc_test::integration::async_::with_future( client, C::default(), &wrpc_test::integration::async_::Something { foo: "bar".to_string(), }, Box::pin(stream::iter(["foo".into(), "bar".into()])), ) .await .context("failed to call `wrpc-test:integration/async.with-future`")?; join!( async { info!("receiving results"); assert_eq!(fut.await.collect::>().await.concat(), b"foobar"); }, async { if let Some(io) = io { info!("performing I/O"); io.await.expect("failed to complete async I/O"); } } ); Ok(()) }