4 ms·
No. There’s no clean async abstraction later; once you pick a side, you’re stuck with crates that support it. Some popular crates let you pick using flags whi
by wokwokwok 6y ago
No.
There’s no clean async abstraction later; once you pick a side, you’re stuck with crates that support it.
Some popular crates let you pick using flags which one you want when you add them... but, tldr: no.
It’s not ideal, but it’s very flexible.
Given they weren’t sure exactly what the async runtime should look like, and the strong backwards compatibility promise, they opted for “get something people can use for now”.
...of course, the python packaging story shows this is a stupid idea in the long run, and I believe the plan is to consolidate into a single “std” async runtime eventually.
...but for now, in your situation, you’re basically screwed I’m afraid. Fork the crate and migrate it yourself is probably the only real solution.
The downside is that doing that usually unearths dependencies that are also using the wrong runtime, etc.
For now: Pick one, stick with it.
- swsieber 6y agoI think smoke is trying to be that abstraction layer? I know it makes it easy to swap out the runtime.
- Matthias247 6y agoThe issue with abstraction layers is typically that they can only offer the minimal amount of common functionality - which is often not good enough. They also have the tendancy to get outdated and non-maintained, since most users will just go for a runtime directly.
- dathinab 6y ago> - which is often not good enough. Except that it mostly should be good enough. async-std tried to mirror rust's libstd, and tokio adapted it. Similar the global `spawn` and the value returned from it work kinda the same +- some naming differences. Even the `LocalExecutor`/`LocalSet` can be abstracted over to erase their differences. That also true for all simple usages of timout. The remaining differences are: - different internal implementation details - naming differences which are not that easy to abstract away - some detail about time/timeout handling I forgot which for many use-cases doesn't matter - the AsyncRead/AsyncWrite traits but this is going to get into std so this will go away soon - some "advanced" features like the fact that tokio overlaps the non-blocking executor thread pool with a blocking worker thread pool, but that in many case not a very important feature. - some differences in e.g. how to specify the number executor threads etc. Most other differences are "old legacy left overs" from the pre-async/await futures time periode. So while a generic in-language abstraction likely won't happen anytime soone one which uses feature flags and re-exports as basis should be very doable in the close future. (I don't know how good the mentioned one is.)
- xfer 6y agoSame thing happened in Ocaml land w.r.t. async vs lwt. Not sure what the current situation is but people had to abstract their libraries and do 2 implementations to support them.
- Matthias247 6y agoThat's not fully correct. A lot of futures will work independent of the runtime. E.g. all the sync primitives/channels/etc from all sources (futures-rs/tokio/async-std/futures-intrusive/etc) will work with all runtimes. Then a lot of objects which require a runtime (e.g. an async socket) might still work on a foreign runtime as long as the original runtime is running. E.g. I think you can use async-std sockets from inside tokio, as long as the async-std runtime is also running in the background. Same is true for the other direction to a certain extent, but it's a bit more complicated to set up. So overall you will need to understand how the runtimes work and if particular pieces can be mixed and matched. If you don't want to invest in that knowledge => stay on one side. And before someone starts to blame the Rust ecosystem for that: It's not really different in any other environment. You can't easily mix and match GTK, QT, libuv and boost asio eventloops. It's event a lot harder than trying to combine Rusts async types.
- pjmlp 6y agoYou can mix and match C++20 co-routines, C#/F#/VB co-routines, Kotlin co-routines, that is the whole idea.
- Matthias247 6y agoI can probably. I guess a few prinicpal/staff engineers can too. But doing cross FFI async function invocations and trying to unify runtimes in that fashion is not a thing that people usually do. And it still wouldn't allow you to call QT socket APIs and Netty socket APIs from the same thread.
- pjmlp 6y agoYou missed the point, the languages I mentioned have it as relevant enough to have the async runtime as part of the standard library, instead of leaving it to 3rd parties.
- Matthias247 6y agoC++ coroutines are not more „part of the standard library“ than rusts async support. One might say it might be less, since they arrived so late in c++ lifetime and more Production libraries have been built without them und mind. And again, they don’t make GTK and Qt and boost Asia eventloops interoperable. Even if you implement co_await support for each of them individually