3 ms·
If you were to write the same code without using async you'd be trudging through a mess of callbacks and combinators. This is what writing futures code before
by treyd 2y ago
If you were to write the same code without using async you'd be trudging through a mess of callbacks and combinators. This is what writing futures code before 2018 was like. It was doable if you needed the perf but it sucked. Async is a huge improvement to readability and reasoning that we didn't have before.
- jeremyjh 2y agoNo, actually that was just javascript. Programming environments with threading models don't have to live that way. Separate threads can communicate through channels and do quite well for themselves. See how it works is, you do something like let data = file.read(); and the it just sits there on that line until the read is done and then your data has the actual bytes in it and you just use them and go on with your life.
- eklavya 2y agoMaybe you are both right but your scales are orders of magnitude apart.
- zozbot234 2y ago> you do something like let data = file.read(); and the it just sits there on that line until the read is done and then your data has the actual bytes in it and you just use them and go on with your life. That's exactly how async/await works, except that it translates to state machines under the hood which gives you great performance. No need to mess with threading models, at all.
- vacuity 2y agoYeah, Rust's async/await and lightweight threads are functionally very similar. Function coloring is a problem with async/awaitt, though (for now?).
- iudqnolq 2y agoUntil you need cancellation
- ragall 2y agoOne rarely really needs that.