Skip to content

Remove manual creation of tokio runtime#8

Merged
molikuner merged 2 commits into
mainfrom
refactor/gh-6-remove-extra-creation-of-runtimes
Jun 13, 2025
Merged

Remove manual creation of tokio runtime#8
molikuner merged 2 commits into
mainfrom
refactor/gh-6-remove-extra-creation-of-runtimes

Conversation

@molikuner

Copy link
Copy Markdown
Collaborator

By leveraging the tokio feature of UniFFI we don't need to manually instantiate the runtime and thus can easily maintain the same code between the BTLB iOS app and the CLI.

Closes #6

By leveraging the tokio feature of UniFFI we don't need to manually
instantiate the runtime and thus can easily maintain the same code
between the BTLB iOS app and the CLI.

GH-6
@q231950

q231950 commented Jun 8, 2025

Copy link
Copy Markdown
Owner

This is awesome, I'll have a look later!

@q231950 q231950 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molikuner this is a fantastic pr, thank you so much! I created a testflight build from BTLB main+ these changes and checked refresh, renewal and search. It all looked great 👍 I love the API refinement that's getting rid of Option and instead returning a future, that's great as well.

Comment thread paper/src/api/api_client.rs Outdated
///
/// # Returns
/// * `Option<String>` - The first URL that returned 200 or None
pub(crate) async fn test_urls(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to ping_urls or validate_urls?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to validate_urls 👍

}

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so this is where the magic happens ☝️

pub(crate) fn search_result_detail_from(
document: scraper::Html,
) -> Option<SearchResultDetail> {
) -> impl Future<Output = SearchResultDetail> + Send {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused be for a moment that the 2 scrapers Opc4v2_13Vzg6SearchDetailScraper/HamburgPublicSearchDetailScraper have similar API with different return types. Nothing you need to change, just something I stumbled upon.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I could remove the Result from Opc4v2_13Vzg6SearchDetailScraper as well, but there would still be the difference of this function being async, while the other function is sync (and it doesn't really make sense to introduce async there for no reason). I'm currently thinking about some other ways to align the APIs, so let's keep it like this for now and followup at a later point.

pub struct RenewalService {}

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked renewal in a TestFlight build 👍

@molikuner
molikuner merged commit 75d62ba into main Jun 13, 2025
1 check passed
@molikuner
molikuner deleted the refactor/gh-6-remove-extra-creation-of-runtimes branch June 13, 2025 18:10
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.

Use uniffi tokio feature and remove creations of extra runtimes

2 participants