-
Notifications
You must be signed in to change notification settings - Fork 225
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
Dealing with Async rust behavior #409
Comments
This is the pattern I’ve used here (but using https://github.com/scrogson/franz/blob/master/native/franz/src/task.rs I’m not sure of a better way at the moment. I think at some point it would be nice to build an abstraction around futures so that we could automatically build NIFs which yield at await points (using |
That would be great to be honest. That's that kind of functionality that I was expecting to see but it makes sense that its not really in here yet given how rustler has changed in the past couple of months. Would also be cool to expose the async functions as something similar to tasks in the elixir/erlang side of things. I would certainly be interesting in contributing for this kind of feature in the future. Thanks for the response. How brittle do you think this pattern is with |
I remember talking about something like this, but that wouldn't actually help in this case. This would simply be an easier way to work with NIFs that reschedule without having to manually split your function into several pieces. The implementation of something like this would require a major refactor/API change in Rustler, and the advantages are arguable, so I don't think this will be done anytime soon.
We would very much like to provide better integration between Rustler and async Rust code. However, we are simply users of the There is no good way to get around having a future runtime, like tokio. For initializing the runtime, you have a couple of options (like you mentioned):
I see no reason why these approaches would be particularly brittle, as long as you avoid blocking the BEAM scheduler thread on the future (avoid Instead, spawn your future in the runtime, and return from the NIF immediately. Then send the result back to your process with One abstraction we could and should provide, is a variant of A function like |
Closing for #411 as it seems like that's about the extent of what we can provide. |
This here, is exactly the kind of advice I was looking for. Thank you very much. I very much look forward to seeing this kind of feature in the future as my code is riddled with |
I am using Rustler to wrap a natively async rust library (features async traits and other such async methods). I am wondering if there is a idiomatic way to deal with futures with rustler without having to pull in a rust executor. Currently, I have a
tokio
runtime loaded in with lazy static but the pattern feels very brittle. I know there are threads in rustler, perhaps theres something there that is useful for dealing with async blocks? or with the Dirty Schedulers? I am not too familiar with the Dirty Schedulers.The text was updated successfully, but these errors were encountered: