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

Add async for I/O calls #372

Merged
merged 9 commits into from
Sep 30, 2024
Merged

Add async for I/O calls #372

merged 9 commits into from
Sep 30, 2024

Conversation

KendallWeihe
Copy link
Contributor

No description provided.

@@ -1,4 +1,5 @@
use crate::errors::Result;
use futures::executor::block_on;
Copy link
Contributor

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?

Copy link
Contributor Author

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)
    }

Copy link
Contributor Author

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

@nitro-neal
Copy link
Contributor

image

@@ -7,6 +7,7 @@ repository.workspace = true
license-file.workspace = true

[dependencies]
futures = "0.3.30"
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@diehuxx diehuxx left a 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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@KendallWeihe KendallWeihe merged commit ef1a319 into main Sep 30, 2024
25 checks passed
@KendallWeihe KendallWeihe deleted the kendall/async-everything branch September 30, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants