Hacker News new | past | comments | ask | show | jobs | submit login

It’s pretty much the same issue all languages have, that async functions are colored. I don’t think it is unique to rust.

Algebraic effects would solve this, but I don’t know any language other than OCaml that is working on that approach.




It’s not just that. There’s a few big problems with Rust async aside from the normal coloring problem that is inherent to async and not worth talking about.

* The async runtime and async functions are decomposed but tightly coupled. That means while you could swap out runtimes, a crate built against one runtime can’t generally be used with another unless explicitly designed to support multiple. I believe C++ has a similar problem but no other major language I’m aware of has this problem - that’s typically because there’s only a single runtime and it’s embedded in the language. Things like timers and I/O are not interoperable because the API you use has to be for the runtime you’re running under. I believe there’s work ongoing to try to remedy this although in practice I think that’s difficult (eg what if you’re using a crate relying on epoll-based APIs but the runtime is io_uring).

* async in traits. I believe that’s coming this year although the extra boxing it forces to make that work makes that not something 0-cost you can adopt in a super hot path.

* async requires pinned types which makes things very complex to manage and is a uniquely Rust concept (in fact I read a conceptually better alternative proposal for how to have solved the pin/unpin problem on HN not too long ago, but that ship has long sailed I fear).

* The borrow checker doesn’t know if your async function is running on a work stealing runtime or not which means there’s a lot more hoop jumping via unsafe if you want optimal performance.

* async functions are lazy and require polling before they do anything. That can be a bit surprising and require weird patterns.

Don’t get me wrong. The effing-mad crate is a fantastic demonstration of the power of algebraic effects to comprehensively solve coloring issues (async, failability, etc). But I think there’s stuff with runtime interop that’s also important. I don’t think anyone is yet seriously tackling improving the borrow checker for thread per core async.


Async in traits feature doesn’t use boxing (which is coming in 28 December), only async-trait crate use boxing.


Really? When I read the GitHub issue it seemed like even the standardized implementation results in boxing…


I mean... that's not really the pain that people are referring to when they are struggling with async Rust, especially when you compare it other languages like JavaScript that also have a difference between async and regular functions.


Unison [1] has algebraic effects as a first-class feature. They call them "abilities" there. You can make async about as transparent/opaque as you want it. Docs on abilities in [2].

[1]: https://www.unison-lang.org/

[2]: https://www.unison-lang.org/learn/language-reference/abiliti...


Does anyone actually use unison in real life?


I don't know that anybody is running a company on it yet, no. They've got a couple big milestones coming down the pike, which might make it more attractive to people.


Can't scala, haskell, (kotlin?) you just lift functions into Async?

You can convert colors simply but only one way, and practically that works, functional core imperative shell, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: