-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make ResponseFuture implement Sync #2653
Conversation
(Chiming in because the last time this came up @seanmonstar asked for a specific use case - I don't feel qualified to comment on the actual diff) It'd help me out as well if Right now, though, with
(It's totally possible there's an easier way to do this that I've missed) |
87be2e0
to
64a2125
Compare
Returning a boxed trait object requires specifying whether the returned future is `Send`/`Sync`, which means we can't support both `Send` and non-`Send` async HTTP clients. The `reqwest` client returns a `Send` future when using versions of `hyper` >= 0.14.14 (see hyperium/hyper#2653), except in WASM builds, for which the future is non-`Send`. With this change, each `request_async()` method now returns `impl Future`, which may or may not be `Send` depending on the inputs. This provides the flexibility to support all the necessary HTTP clients, while providing the convenience of `Send` futures for the built-in `reqwest` client in non-WASM builds. BREAKING CHANGES: - Removed `TokenRequestFuture` and `DeviceAuthorizationRequestFuture` type aliases. - Added `Future` associated type to `AsyncHttpClient` trait and changed `call()` method to return `Self::Future` (which may or may not be `Send`/`Sync`). - Changed each `request_async()` method to return `impl Future` instead of `Pin<Box<dyn Future>>`. Fixes #255 and #260.
Returning a boxed trait object requires specifying whether the returned future is `Send`/`Sync`, which means we can't support both `Send` and non-`Send` async HTTP clients. The `reqwest` client returns a `Send` future when using versions of `hyper` >= 0.14.14 (see hyperium/hyper#2653), except in WASM builds, for which the future is non-`Send`. With this change, each `request_async()` method now returns `impl Future`, which may or may not be `Send` depending on the inputs. This provides the flexibility to support all the necessary HTTP clients, while providing the convenience of `Send` futures for the built-in `reqwest` client in non-WASM builds. BREAKING CHANGES: - Removed `TokenRequestFuture` and `DeviceAuthorizationRequestFuture` type aliases. - Added `Future` associated type to `AsyncHttpClient` trait and changed `call()` method to return `Self::Future` (which may or may not be `Send`/`Sync`). - Changed each `request_async()` method to return `impl Future` instead of `Pin<Box<dyn Future>>`. Fixes #255 and #260.
Returning a boxed trait object requires specifying whether the returned future is `Send`/`Sync`, which means we can't support both `Send` and non-`Send` async HTTP clients. The `reqwest` client returns a `Send` future when using versions of `hyper` >= 0.14.14 (see hyperium/hyper#2653), except in WASM builds, for which the future is non-`Send`. With this change, each `request_async()` method now returns `impl Future`, which may or may not be `Send` depending on the inputs. This provides the flexibility to support all the necessary HTTP clients, while providing the convenience of `Send` futures for the built-in `reqwest` client in non-WASM builds. BREAKING CHANGES: - Removed `TokenRequestFuture` and `DeviceAuthorizationRequestFuture` type aliases. - Added `Future` associated type to `AsyncHttpClient` trait and changed `call()` method to return `Self::Future` (which may or may not be `Send`/`Sync`). - Changed each `request_async()` method to return `impl Future` instead of `Pin<Box<dyn Future>>`. Fixes ramosbugs#255 and ramosbugs#260.
By using the
SyncWrapper
utility we can makeResponseFuture
implement theSync
trait. The fact that it doesn't currently can propagate up through many layers of types and cause annoying compilation errors about things that are not really an issue.