From 9b3bd3f0e0f2efef2a86c6e71b2c5f2a8035c394 Mon Sep 17 00:00:00 2001 From: Jason Boatman Date: Fri, 8 Jan 2021 14:04:14 -0500 Subject: [PATCH 1/2] Upgraded to tokio 1.0, fixed building outside of the crate and reduced the number of futures based dependencies. --- Cargo.toml | 8 +++++--- src/lib.rs | 15 +++++++-------- src/runtime.rs | 15 ++++----------- src/time.rs | 4 ++-- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 12fbd83..7407c4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,15 +17,17 @@ default = ["tokio", "unstable"] unstable = [] [dependencies] -futures = "0.3" -tokio = { version = "0.3", features=["rt", "time"], optional = true } +futures-core = "0.3" +futures-channel = { version = "0.3", features=["sink"] } +futures-util = { version = "0.3", features=["sink"] } +tokio = { version = "1", features=["rt", "rt-multi-thread", "time"], optional = true } async-std = { version = "1.0", features=["unstable"], optional = true } async-trait = "0.1" futures-timer = "3.0.2" log = "0.4" [dev-dependencies] -tokio = { version = "0.3", features = ["full"] } +tokio = { version = "1", features = ["full"] } tokio-postgres = "=0.6.0" env_logger = "0.7" tide = "0.5" diff --git a/src/lib.rs b/src/lib.rs index 0831e5b..33a5927 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,13 +81,13 @@ mod time; pub use async_trait::async_trait; pub use config::Builder; use config::{Config, InternalConfig, ShareConfig}; -use futures::channel::mpsc::{self, Receiver, Sender}; -use futures::channel::oneshot::{self, Sender as ReqSender}; -use futures::lock::{Mutex, MutexGuard}; -use futures::select; -use futures::FutureExt; -use futures::SinkExt; -use futures::StreamExt; +use futures_channel::mpsc::{self, Receiver, Sender}; +use futures_channel::oneshot::{self, Sender as ReqSender}; +use futures_util::lock::{Mutex, MutexGuard}; +use futures_util::select; +use futures_util::FutureExt; +use futures_util::SinkExt; +use futures_util::StreamExt; pub use spawn::spawn; use std::collections::HashMap; use std::error; @@ -818,4 +818,3 @@ impl DerefMut for Connection { self.conn.as_mut().unwrap().raw.as_mut().unwrap() } } - diff --git a/src/runtime.rs b/src/runtime.rs index 4497ed5..2515af1 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -3,7 +3,7 @@ pub use runtime::{DefaultExecutor, Runtime, TaskExecutor}; -use futures::Future; +use std::future::Future; use std::pin::Pin; // A new type exports the default executor of Tokio.. @@ -20,24 +20,20 @@ pub trait Executor: Send + Sync + 'static + Clone { fn spawn(&mut self, future: Pin + Send>>); } -#[cfg(all( - feature = "tokio", - not(feature = "async-std") -))] +#[cfg(all(feature = "tokio", not(feature = "async-std")))] mod runtime { use super::*; /// Wrapper of the Tokio Runtime - pub struct Runtime{ + pub struct Runtime { rt: tokio::runtime::Runtime, spawner: TaskExecutor, } - impl Runtime { /// Creates a new Runtime pub fn new() -> Option { - Some(Runtime{ + Some(Runtime { rt: tokio::runtime::Runtime::new().unwrap(), spawner: TaskExecutor, }) @@ -67,7 +63,6 @@ mod runtime { } } - /// Simple handler for spawning task #[derive(Clone)] pub struct TaskExecutor; @@ -101,7 +96,6 @@ mod runtime { } } - #[cfg(all(feature = "async-std"))] mod runtime { use super::*; @@ -147,7 +141,6 @@ mod runtime { } } - #[derive(Clone)] pub struct DefaultExecutor; diff --git a/src/time.rs b/src/time.rs index 31b109e..d984b25 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,5 +1,5 @@ use crate::Error; -use futures::FutureExt; +use futures_util::{select, FutureExt}; use std::future::Future; use std::time::Duration; pub use time::{delay_for, interval}; @@ -8,7 +8,7 @@ pub(crate) async fn timeout(duration: Duration, f: F) -> Result>>, { - futures::select! { + select! { () = delay_for(duration).fuse() => Err(Error::Timeout), rsp = f.fuse() => rsp, } From 91dc040707009aaa441d12a7ae1107f898083eff Mon Sep 17 00:00:00 2001 From: Jason Boatman Date: Fri, 8 Jan 2021 14:48:08 -0500 Subject: [PATCH 2/2] Fix the tests --- tests/mobc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/mobc.rs b/tests/mobc.rs index 06c0b48..858e598 100644 --- a/tests/mobc.rs +++ b/tests/mobc.rs @@ -967,12 +967,12 @@ fn test_timeout_when_db_has_gone() { type Error = TestError; async fn connect(&self) -> Result { - futures::future::pending::<()>().await; + futures_util::future::pending::<()>().await; Ok(Connection) } async fn check(&self, conn: Self::Connection) -> Result { - futures::future::pending::<()>().await; + futures_util::future::pending::<()>().await; Ok(conn) } } @@ -1007,7 +1007,7 @@ fn test_timeout_when_db_has_gone2() { async fn connect(&self) -> Result { if self.0.load(Ordering::Relaxed) > 0 { - futures::future::pending::<()>().await; + futures_util::future::pending::<()>().await; } else { self.0.fetch_add(1, Ordering::Relaxed); } @@ -1016,7 +1016,7 @@ fn test_timeout_when_db_has_gone2() { async fn check(&self, conn: Self::Connection) -> Result { if self.0.load(Ordering::Relaxed) > 0 { - futures::future::pending::<()>().await; + futures_util::future::pending::<()>().await; } Ok(conn) }