-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add async for I/O calls #372
Conversation
@@ -1,4 +1,5 @@ | |||
use crate::errors::Result; | |||
use futures::executor::block_on; |
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 futures::executor::block_on
vs alternatives like tokio::task::spawn_blocking
?
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.
futures
has a slightly more streamlined error handling, whereas with tokio I would have to add a mapper into our error type, see the unwrap
below
pub fn resolve(uri: &str) -> Self {
let inner_result = task::spawn_blocking(move || {
tokio::runtime::Handle::current().block_on(InnerResolutionResult::resolve(uri))
}).unwrap(); // Handle unwrap or any error handling as required.
Self(inner_result)
}
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.
Weird, I guess uniffi requires tokio? I could've sworn I tested with futures, but oh well, guess I have to go the tokio route
@@ -7,6 +7,7 @@ repository.workspace = true | |||
license-file.workspace = true | |||
|
|||
[dependencies] | |||
futures = "0.3.30" |
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.
When we chatted at standup, you were getting an error similar to this mozilla/uniffi-rs#2223. The solution may be that we have to specify async_runtime = tokio using uniffi proc macros as described here mozilla/uniffi-rs#2219.
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.
indeed! good catch, we can improve this later
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.
broadly this looks good. any details we can clean up in subsequent PRs.
Method::Get => "GET".to_string(), | ||
Method::Post => "POST".to_string(), | ||
Method::Put => "PUT".to_string(), | ||
impl fmt::Display for Method { |
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.
did you mean to change the name?
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.
Yeah I learned that implementing Display
is slightly preferable to implementing ToString
because implementing Display
also implements ToString
plus you get format!()
support
No description provided.