5 ms·
> and I don't understand the relationship of Tokio and the language's async/await syntax. One of the surprising things with rust here, is that it define only t
by mamcx 7y ago
> and I don't understand the relationship of Tokio and the language's async/await syntax.
One of the surprising things with rust here, is that it define only the syntax and some bare traits AND ALLOW TO PLUG ANY RUNTIME.
This mean you can "swap" runtime implementations and even build your own.
One recent example is:
https://www.reddit.com/r/rust/comments/g917ad/smol_stjepang_a_small_and_fast_async_runtime_for/ https://www.reddit.com/r/rust/comments/g917ad/smol_stjepang_...
This is in contrast with Go/Erlang/.NET, etc where the runtime for it is made for you, but can't be changed. This is cool where things are mostly fine all the time, but rust being a SYSTEM lang allow this is neat (example: Embebed scenarios where a regular runtime is too heavy).
Note: This template show in other places, where for example you can swap the allocator or the (default) hash function.
- steveklabnik 7y agoI should also note, for balance, that this isn't perfect today. There are still some missing bits to make it truly "plug anything anywhere," but it's pretty close.
- sdegutis 7y agoThe main thing I don't understand about Rust's async/await situation is how it's not very inefficient on the CPU given that it fundamentally uses polling? https://doc.rust-lang.org/std/future/trait.Future.html https://doc.rust-lang.org/std/future/trait.Future.html
- carllerche 7y agoThe model is very similar to how epoll works. The executor does not poll futures in a loop. Between polls, the executor waits for a readiness notification. If `Future::poll` returns Pending, once it becomes ready to do more work, it notifies the executor, the executor then schedules the future to be polled again.
- mamcx 7y agoI suspect that a big part of the design of this api (and why it take time) was exactly to be as performant as possible. The compiler desugar the async/await to state machines and that is melted away by regular means. Also, the quality of the runtime elected must take some credit.
- aliceryhl 7y agoIt doesn't poll all the time. The context parameter contains a walker, and you have to tell the executor to wake you up using that waker when you are ready to continue.
- dralley 7y agoWas Python the first language to do async that way? I know within the Python ecosystem you've got asyncio, Trio, Curio, etc.
- vips7L 7y agoSo it's sort of like the javax API?
- pjmlp 7y agoActive Oberon, Ada and C++ are system languages and have default implementations as part of the standard.
- alvarelle 7y agoI don't know about the others, but C++ don't have a default implementation as part of the standard. If you want an event loop, you need to use one of the many libraries that provide one.
- pjmlp 7y agoC++20 surely has one.
- alvarelle 7y agoNo, it hasn't. Actually C++20 comes with only the minimal support for coroutines in the std library. If you want to do anything useful, you need to implement a promise type yourself which is very hard to do without using one library that does that.
- pjmlp 7y agoFrom the looks of it, and what I am already able to do with Visual C++ I bet it still is more functional than what Rust currently offers. And that I won't need to rewrite it when I try out the same code with another C++20 compiler.