-
Notifications
You must be signed in to change notification settings - Fork 251
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
check core for wasm #228
check core for wasm #228
Conversation
An error I received was: Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely Which led me to rustwasm/wasm-bindgen#2409 and then do the async_trait docs which say:
It worked for compiling azure_core but may cascade changes. I could use some help understanding the impact. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It compiles. 🥳 I'm sure I broke some stuff regarding Send
. Conceptually, do we need the clients implementing Send
? Please review in detail.
sdk/core/src/http_client.rs
Outdated
@@ -92,7 +94,8 @@ impl HttpClient for hyper::Client<HttpsConnector<hyper::client::HttpConnector>> | |||
} | |||
} | |||
|
|||
#[async_trait] | |||
#[cfg(feature = "enable_reqwest")] | |||
#[async_trait(?Send)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change appears to have a cascading effect. https://docs.rs/async-trait/0.1.48/async_trait/#non-threadsafe-futures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg_attr to the rescue! I've disabled Send from wasm builds only. Thanks to:
dtolnay/async-trait#159 (comment)
} | ||
} | ||
// TODO | ||
// pub fn with_client(client: Arc<Box<dyn HttpClient>>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you post the compiler error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS C:\Users\cataggar\io\azure-sdk-for-rust> cargo check
Checking azure_cosmos v0.1.0 (C:\Users\cataggar\io\azure-sdk-for-rust\sdk\cosmos)
error: future cannot be sent between threads safely
--> sdk\cosmos\src\clients\cosmos_client.rs:51:17
|
51 | Box::pin(async move { Ok(client.execute_request(req).await?.into()) })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
|
= help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Output = Result<http::Response<bytes::Bytes>, Box<dyn StdError + Sync + std::marker::Send>>>`
note: future is not `Send` as it awaits another future which is not `Send`
--> sdk\cosmos\src\clients\cosmos_client.rs:51:42
|
51 | Box::pin(async move { Ok(client.execute_request(req).await?.into()) })
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here on type `Pin<Box<dyn futures::Future<Output = Result<http::Response<bytes::Bytes>, Box<dyn StdError + Sync + std::marker::Send>>>>>`, which is not `Send`
= note: required for the cast to the object type `dyn futures::Future<Output = Result<azure_core::Response, Box<(dyn StdError + Sync + std::marker::Send + 'static)>>> + std::marker::Send`
@@ -13,7 +13,7 @@ categories = ["api-bindings"] | |||
edition = "2018" | |||
|
|||
[dependencies] | |||
azure_core = { path = "../core", version = "0.1.0" } | |||
azure_core = { path = "../core", version = "0.1.0", features = ["enable_hyper"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping this is temporary. We can create an issue to make event_grid
not require hyper.
@@ -122,6 +127,19 @@ impl HttpClient for reqwest::Client { | |||
} | |||
} | |||
|
|||
// wasm can not get the http version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I try to use it, I get:
PS C:\Users\cataggar\io\azure-sdk-for-rust> cargo check -p azure_core --target=wasm32-unknown-unknown
Blocking waiting for file lock on build directory
Checking azure_core v0.1.0 (C:\Users\cataggar\io\azure-sdk-for-rust\sdk\core)
error[E0599]: no method named `version` found for reference `&reqwest::Response` in the current scope
--> sdk\core\src\http_client.rs:140:19
|
140 | Some(response.version())
| ^^^^^^^ method not found in `&reqwest::Response`
The code shows this:
https://github.com/seanmonstar/reqwest/blob/1614c5ea64813ba24d268a2af22ab0d19b902bdf/src/wasm/response.rs#L67-L73
/* It might not be possible to detect this in JS?
/// Get the HTTP `Version` of this `Response`.
#[inline]
pub fn version(&self) -> Version {
self.http.version()
}
*/
} | ||
} | ||
// TODO | ||
// pub fn with_client(client: Arc<Box<dyn HttpClient>>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you post the compiler error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supporting wasm is definitely something we want. I think this needs some work though before we merge.
I love this ❤️! I am not clear why we can't have |
#[async_trait] | ||
#[cfg(feature = "enable_reqwest")] | ||
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] | ||
#[cfg_attr(not(target_arch = "wasm32"), async_trait)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about cfg_attr
, but thanks to dtolnay/async-trait#159 (comment), it works perfectly. Send
is only disabled for wasm builds. Everything else works as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me.
Nice work! 👍
For #37. This allows azure_core to target wasm. This builds off the http client work. It adds two features: