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

Document that blocking and async do not mix #1159

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl ClientBuilder {
///
/// This method fails if TLS backend cannot be initialized, or the resolver
/// cannot load the system configuration.
///
/// # Panics
///
/// This method panics if called from within an async runtime. See docs on
/// [`reqwest::blocking`][crate::blocking] for details.
pub fn build(self) -> crate::Result<Client> {
ClientHandle::new(self).map(|handle| Client { inner: handle })
}
Expand Down Expand Up @@ -606,6 +611,9 @@ impl Client {
///
/// Use `Client::builder()` if you wish to handle the failure as an `Error`
/// instead of panicking.
///
/// This method also panics if called from within an async runtime. See docs
/// on [`reqwest::blocking`][crate::blocking] for details.
pub fn new() -> Client {
ClientBuilder::new().build().expect("Client::new()")
}
Expand Down
7 changes: 7 additions & 0 deletions src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
//! The blocking `Client` will block the current thread to execute, instead
//! of returning futures that need to be executed on a runtime.
//!
//! Conversely, the functionality in `reqwest::blocking` must *not* be executed
//! within an async runtime, or it will panic when attempting to block. If
//! calling directly from an async function, consider using an async
//! [`reqwest::Client`][crate::Client] instead. If the immediate context is only
//! synchronous, but a transitive caller is async, consider changing that caller
//! to use [`tokio::task::spawn_blocking`] around the calls that need to block.
//!
//! # Optional
//!
//! This requires the optional `blocking` feature to be enabled.
Expand Down