2 ms·
Sure, you can technically call other rust code from async rust and thus you can also technically call C code via FFI, but if that code blocks you have a problem
by ithkuil 5y ago
Sure, you can technically call other rust code from async rust and thus you can also technically call C code via FFI, but if that code blocks you have a problem. There are ways around it but they are hard to use and create the pressure towards just rewriting the whole thing in rust.
I could be wrong though. The reason I like to discuss these things here is the opportunity to be proven wrong by someone who knows more and offers a counter-example
- maxthegeek1 5y agoIf you need to call blocking code from an async code just use spawn_blocking. https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.ht...
- ithkuil 5y agoYes you can. And this will create threads on demand as needed. But you need to know when you must call this and when it's ok to not call it. The type system won't help you with that. But if you forget to call it you can cause starvation and if you call it too often you may create too many threads. What I see in the ecosystem is that such tricks are perceived as hacks and that it would be just better if one could just write a pure rust reimpl. Surely there are enough reasons that drive people to reimplements stuff in rust. I think this aspect of async nudges people even further into that though.