diff --git a/src/lib.rs b/src/lib.rs index 3146fad..389657c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -213,13 +213,14 @@ impl< T: Serialize + DeserializeOwned + Unpin + Send + 'static, > AsyncReadConverse { - /// Spawns a future onto the tokio runtime that will drive the receive mechanism. - /// This allows you to receive replies to your messages, while completely ignoring any non-reply messages you get. + /// Returns a future that will drive the receive mechanism. It's recommended to spawn this onto an `async` + /// runtime, such as `tokio`. This allows you to receive replies to your messages, while completely + /// ignoring any non-reply messages you get. /// /// If instead you'd like to see the non-reply messages then you'll need to drive the `Stream` implementation /// for `AsyncReadConverse`. - pub fn drive_forever(mut self) { - tokio::spawn(async move { while StreamExt::next(&mut self).await.is_some() {} }); + pub async fn drive_forever(mut self) { + while StreamExt::next(&mut self).await.is_some() {} } } diff --git a/src/tests.rs b/src/tests.rs index 51beba5..bfc7fdf 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -168,7 +168,7 @@ async fn basic_dialogue() { new_duplex_connection(ChecksumEnabled::Yes, server_read, server_write); let (mut client_read, _client_write) = new_duplex_connection(ChecksumEnabled::Yes, client_read, client_write); - server_read.drive_forever(); + tokio::spawn(server_read.drive_forever()); tokio::spawn(async move { while let Some(message) = client_read.next().await { let mut received_message = message.unwrap(); @@ -278,7 +278,7 @@ async fn timeout_check() { new_duplex_connection(ChecksumEnabled::Yes, server_read, server_write); let (mut client_read, _client_write) = new_duplex_connection(ChecksumEnabled::Yes, client_read, client_write); - server_read.drive_forever(); + tokio::spawn(server_read.drive_forever()); tokio::spawn(async move { while let Some(message) = client_read.next().await { let mut received_message = message.unwrap();