You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just wanted to point out a use case I have that is not well supported.
Sometimes a function may, or may not require async_runtime = "tokio" depending what happens at runtime. There seems to be no way to conditionally require tokio with uniffi based on runtime considerations.
In my project, Im creating a struct Hyperbee. It can be backed by data either on disk, or in memory.
When the struct is created from data on disk, it uses tokio::fs to read from disk, so it needs tokio. When backed by memory, it doesn't need tokio.
This appeared in a somewhat surprising way, my tests were failing based on how my struct was constructed. Even after I marked just the constructor function with async_runitem = "tokio". Since the structs methods would read from disk when called.
The only solution I could think of was to just mark everything that could potentially require tokio with async_runtime = "tokio" so that is what I ended up doing. This works but seems less than optimal. I there is a better way please let me know!
The text was updated successfully, but these errors were encountered:
I just ran into the exact same issue and this comment helped me a lot @flisky.
Already had my own instance of the runtime configured the same way but struggled to inject it in async_compat at all cases, and running an empty future wrapped in it on the runtime once is a great trick.
In my opinion this is worth being mentioned in the docs, maybe next to the JNI config in the Gradle section.
I just wanted to point out a use case I have that is not well supported.
Sometimes a function may, or may not require
async_runtime = "tokio"
depending what happens at runtime. There seems to be no way to conditionally require tokio with uniffi based on runtime considerations.In my project, Im creating a struct
Hyperbee
. It can be backed by data either on disk, or in memory.When the struct is created from data on disk, it uses
tokio::fs
to read from disk, so it needs tokio. When backed by memory, it doesn't need tokio.This appeared in a somewhat surprising way, my tests were failing based on how my struct was constructed. Even after I marked just the constructor function with
async_runitem = "tokio"
. Since the structs methods would read from disk when called.The only solution I could think of was to just mark everything that could potentially require tokio with
async_runtime = "tokio"
so that is what I ended up doing. This works but seems less than optimal. I there is a better way please let me know!The text was updated successfully, but these errors were encountered: