@Mikra, It's nice to find another Joe Duffy fan. His posts are long, but always 
super interesting!

Actually, Nim's implementation of async is actually _very_ similar to the C# 
version, which is very similar to the Node version, which is how old Python did 
it.

TLDR; they all read the same papers and did similar things. Our async is also 
just a _front end compiler trick_ (that is just another phrase for _macro_ ).

We specifically implement our async very similar to how Python did it before 
Python 2.5( @see: 
[https://en.wikipedia.org/wiki/Coroutine#Comparison_with_generators](https://en.wikipedia.org/wiki/Coroutine#Comparison_with_generators))

But this trick is used in many languages that have generators, but can't 
manipulate the stack at a low level (including C# and Node.js).

Generator macros is a _very_ elegant hack, but, It's not the most efficient way 
to implement async. Native runtime support with split stacks is better, as Joe 
Duffy describes in his post. This is what newer Python implementations and 
Midori do.

This would be hard to do in Nim because we don't have a lot of control over the 
stack (since we compile to C). It's called "Duff's device".

@See here for more details: 
[https://en.wikipedia.org/wiki/Coroutine#Implementations_for_C](https://en.wikipedia.org/wiki/Coroutine#Implementations_for_C)
 and here: 
[https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html](https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html)

Nim could probably do it (we support inline assembly), but it would be ugly and 
not very cross platform.

Reply via email to