Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace futures-channel with tokio::sync in blocking client #748

Merged
merged 1 commit into from Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Expand Up @@ -25,7 +25,7 @@ default-tls-vendored = ["default-tls", "native-tls/vendored"]

#rustls-tls = ["hyper-rustls", "tokio-rustls", "webpki-roots", "rustls", "tls"]

blocking = ["futures-channel", "futures-util/io", "tokio/rt-threaded", "tokio/rt-core"]
blocking = ["futures-util/io", "tokio/rt-threaded", "tokio/rt-core", "tokio/sync"]

cookies = ["cookie_crate", "cookie_store"]

Expand Down Expand Up @@ -83,9 +83,6 @@ tokio-tls = { version = "0.3.0", optional = true }
#tokio-rustls = { version = "=0.12.0-alpha.2", optional = true }
#webpki-roots = { version = "0.17", optional = true }

## blocking
futures-channel = { version = "0.3.0", optional = true }

## cookies
cookie_crate = { version = "0.12", package = "cookie", optional = true }
cookie_store = { version = "0.10", optional = true }
Expand Down
20 changes: 9 additions & 11 deletions src/blocking/client.rs
Expand Up @@ -5,10 +5,8 @@ use std::sync::Arc;
use std::thread;
use std::time::Duration;

use futures_channel::{mpsc, oneshot};
use futures_util::{StreamExt, TryFutureExt};

use log::{error, trace};
use tokio::sync::{mpsc, oneshot};

use super::request::{Request, RequestBuilder};
use super::response::Response;
Expand Down Expand Up @@ -588,7 +586,7 @@ impl ClientHandle {
fn new(builder: ClientBuilder) -> crate::Result<ClientHandle> {
let timeout = builder.timeout;
let builder = builder.inner;
let (tx, rx) = mpsc::unbounded::<(async_impl::Request, OneshotResponse)>();
let (tx, rx) = mpsc::unbounded_channel::<(async_impl::Request, OneshotResponse)>();
let (spawn_tx, spawn_rx) = oneshot::channel::<crate::Result<()>>();
let handle = thread::Builder::new()
.name("reqwest-internal-sync-runtime".into())
Expand Down Expand Up @@ -621,7 +619,7 @@ impl ClientHandle {

let mut rx = rx;

while let Some((req, req_tx)) = rx.next().await {
while let Some((req, req_tx)) = rx.recv().await {
let req_fut = client.execute(req);
tokio::spawn(forward(req_fut, req_tx));
}
Expand Down Expand Up @@ -659,7 +657,7 @@ impl ClientHandle {
.tx
.as_ref()
.expect("core thread exited early")
.unbounded_send((req, tx))
.send((req, tx))
.expect("core thread panicked");

let result: Result<crate::Result<async_impl::Response>, wait::Waited<crate::Error>> =
Expand All @@ -670,10 +668,10 @@ impl ClientHandle {
};
wait::timeout(f, self.timeout.0)
} else {
wait::timeout(
rx.map_err(|_canceled| event_loop_panicked()),
self.timeout.0,
)
let f = async move {
rx.await.map_err(|_canceled| event_loop_panicked())
};
wait::timeout(f, self.timeout.0)
};

match result {
Expand Down Expand Up @@ -703,7 +701,7 @@ where
Poll::Ready(val) => Poll::Ready(Some(val)),
Poll::Pending => {
// check if the callback is canceled
futures_core::ready!(tx.poll_canceled(cx));
futures_core::ready!(tx.poll_closed(cx));
Poll::Ready(None)
}
}
Expand Down