-
Notifications
You must be signed in to change notification settings - Fork 234
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
Tokio runtimes and async #1726
Comments
Yes we are using this, and we are patching However, the main reason we are accessing the runtime directly is that we still use a bunch of |
Yeah, I'm not sure if I love the ergonomics of my proposal. If the main point is thread pools another option would be for UniFFI doesn't do any wrapping and requires that users manually call |
I agree that the current What I don't feel clear with your proposal is: how is it supposed to work? It's focusing on defining a We would need a way to express we want to wrap the outgoing #[uniffi::export(async_wraps_with = future_wrapper)]
pub async fn foo(…) -> … { }
fn future_wrapper<F, T>(future: F) -> F
where F: Future<Output = T>>
{
// … fetch `Runtime` from somewhere
// build a new `Future` that uses `Runtime`
// i.e. it simply is a “custom re-implementation” of `async_compat::Compat`.
} Thoughts? Edit: I believe that with this proposed design, it's even possible to simply write |
@Hywan I don't think we should be over-abstracting things. There isn't really a use case for this outside of tokio compatibility, is there? I think there's a discussion to be had on whether tokio compat should be something UniFFI bothers with at all, but if it does I don't see much merit to abstracting it such that it can theoretically handle things other than tokio, that nobody actually needs. |
My proposal allows to choose the runtime and to configure the runtime you want per function. It can be a nice feature to have actually :-). |
Well, other runtimes don't need explicit compatibility code like tokio does. The only other major runtime, |
We've a vaguely-defined use-case that would like to choose the runtime dynamically at runtime (roughly, a kind of adaptor that would either want to use an async stack supplied by the foreign code or supplied by a Rust implementation, depending on the environment the code finds itself in) - @bendk is working through making that more concrete though... |
I've been thinking about the current async_runtime support and wondering how useful it is:
async-mutex
andasync-timer
What if instead of using
async-compat
, we allowed users to specify a function that returns a type that derefs totokio::Runtime
and let them build their own runtime? Something like:Then inside the scaffolding function, we do what
async-compat
does and enter the runtime before polling the future.I'm not sure that this is how it should work though. @jplatte @Hywan are you currently using UniFFI async with tokio? If so, how does it work?
The text was updated successfully, but these errors were encountered: