From b611f23f98e7e924f4d62b6b6f2698199e68b3c5 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Tue, 25 Apr 2023 16:20:58 +0200 Subject: [PATCH] Reduce usage of the futures crate --- async-nats/Cargo.toml | 2 +- async-nats/examples/multiple_subs.rs | 2 +- async-nats/src/lib.rs | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/async-nats/Cargo.toml b/async-nats/Cargo.toml index ad16e3e0d..1c87d197e 100644 --- a/async-nats/Cargo.toml +++ b/async-nats/Cargo.toml @@ -16,7 +16,7 @@ categories = ["network-programming", "api-bindings"] [dependencies] memchr = "2.4" bytes = "1.4.0" -futures = { version = "0.3.26", default-features = false, features = ["std", "async-await"] } +futures = { version = "0.3.26", default-features = false, features = ["alloc"] } nkeys = "0.2.0" once_cell = "1.17.1" regex = "1.7.1" diff --git a/async-nats/examples/multiple_subs.rs b/async-nats/examples/multiple_subs.rs index f35f72d48..e9e51c446 100644 --- a/async-nats/examples/multiple_subs.rs +++ b/async-nats/examples/multiple_subs.rs @@ -61,7 +61,7 @@ async fn main() -> Result<(), async_nats::Error> { }); // run both publishing tasks in parallel and gather the results. - match futures::try_join!(foo_pub_handle, bar_pub_handle) { + match tokio::try_join!(foo_pub_handle, bar_pub_handle) { Ok((foo_duration, bar_duration)) => println!( "finished publishing foo in {:?} and bar in {:?}", foo_duration?, bar_duration? diff --git a/async-nats/src/lib.rs b/async-nats/src/lib.rs index b1eba7f68..781a91fb0 100644 --- a/async-nats/src/lib.rs +++ b/async-nats/src/lib.rs @@ -102,9 +102,8 @@ use thiserror::Error; -use futures::future::FutureExt; -use futures::select; use futures::stream::Stream; +use tokio::select; use tracing::{debug, error}; use core::fmt; @@ -339,7 +338,7 @@ impl ConnectionHandler { ) -> Result<(), io::Error> { loop { select! { - _ = self.ping_interval.tick().fuse() => { + _ = self.ping_interval.tick() => { self.pending_pings += 1; if let Err(_err) = self.connection.write_op(&ClientOp::Ping).await { self.handle_disconnect().await?; @@ -348,12 +347,12 @@ impl ConnectionHandler { self.handle_flush().await?; }, - _ = self.flush_interval.tick().fuse() => { + _ = self.flush_interval.tick() => { if let Err(_err) = self.handle_flush().await { self.handle_disconnect().await?; } }, - maybe_command = receiver.recv().fuse() => { + maybe_command = receiver.recv() => { match maybe_command { Some(command) => if let Err(err) = self.handle_command(command).await { error!("error handling command {}", err); @@ -364,7 +363,7 @@ impl ConnectionHandler { } } - maybe_op_result = self.connection.read_op().fuse() => { + maybe_op_result = self.connection.read_op() => { match maybe_op_result { Ok(Some(server_op)) => if let Err(err) = self.handle_server_op(server_op).await { error!("error handling operation {}", err);