Hacker News new | ask | show | jobs
by skrebbel 4236 days ago
Having recently learned Elixir, I really wonder why the C# people decided to add async/await rather than coroutines (like Erlang processes or Goroutines).

It feels to me like async/await is the malloc of concurrent programming, and coroutines are the garbage collection of concurrent programming. You hand in a little performance in exchange for a lot less complexity. Go has shown you can also do this without only-immutable data.

Am I missing something?

2 comments

Mainly because the CLR and Windows do not support segmented stacks, and supposedly supporting them would be almost impossible while preserving interop with native code.

Without segmented stacks you have to conserve threads, which basically leads to Task and async/await.

Edit: Almost forgot a important part: your COM thread is hugely important to how Windows UI pumping works. Async guarantees what thread you get to run on, where coroutines often just say, "you get the thread that you get."

C# await is a low level level construct that you can use to efficiently implement coroutines. The opposite is not true. Anders&Co designed a tool that has some rough edges (compared to say F# async computation expressions), but compiles to a small amount of low overhead Task operations.