I’m new to the Zig community, so sorry If this is already an obsolete topic.
When discussing async/await and stackful/stateless coroutines, it seems that rarely any person in Zig community mentions the way JavaScript does with its generator functions (not asnyc/await), which is a combination of stackful/stackless design. You can always use generators to create your own async scheduler without async/await, converting the push-like behavior of async/await into a polling way.
Since Zig doesn’t have generator functions, it seems neutral to provide a similar grammer that can be used in both the async/await and complex iterating scenarios.
What are the considerations that Zig did not do async/await with generators?
Welcome to Ziggit @pinyin!
Javascript generators are stackless: it’s only possible to yield
from the body of the generator itself, it can’t (automatically) yield from functions that the generator called.
When Zig had async
it was possible to construct that kind of generator using it. The feature caused problems for the rest of the language, and we won’t get it back unless those problems can all be solved. I’d like to see that happen, personally, but it appears to be the kind of unsolved problem which can only be solved by writing research papers, not just reading enough of them.
So when it did have async
, you could make generators with async, rather than making ‘async’ with generators. Zig is a language which gives the user the fundamental building blocks, and trusts/expects them to use those to build the higher-level patterns which the code might need.
Hi @mnemnion ,
I see your point about the difficulty around this async/await problem. JS generators solved the two colored functions problem but at the expense of passing iterables everywhere, which does seem to be luxurious for any system language.
And just like the community often refers to, other languages like Rust has also had a long debate over async/await and there are many users not very pleasant with what they are getting.
Leaving the problem for later is quite understandable after your explanation.
Thanks for your welcome, and for the detailed explanations.