3 ms·
This is only true if you are building the implementation of async/await as a compilation hack (maybe a "transpiler", as people now like to say) rather than as a
by saurik 12y ago
This is only true if you are building the implementation of async/await as a compilation hack (maybe a "transpiler", as people now like to say) rather than as a feature of the virtual machine. You don't need "threads" to implement this, you just need the ability to work with multiple stacks and then have use the techniques from coroutines. (Some people call this "green threads", but that's not the kind of "threads" you would refer to when saying C# has threads.)
I imagine the reason they avoided doing this was to not require browser vendors to make half their browser internals safe for usage in reasonable coroutines ;P. I can also see them having wanted to guarantee that the feature could be implemented using a transpiler rather than requiring it to be a native feature of the browser, and generators being explicitly marked at both the declaration and call sites (or async await with the limitations you mention) have that property by allowing a continuation passing transform to be applied to the generator's code. (Which could be applied to all code, of course, but not native browser code. edit: Well, you could so that as well, but it would violate other assumptions about how the code is supposed to work, and isn't something anyone has infrastructure to accomplish ;P.)
- emn13 12y agoTo condense what you're saying to its core: you can avoid the need to make callers async if you simply make everything async. In essence, that's the choice Go made. It's certainly simpler for the programmer. It probably makes optimization trickier, and it probably makes efficient parallelism harder (since real threads are completely abstracted away, the VM needs to understand when to start real threads, and when to use promises). For a language like javascript, it sounds like these tradeoffs are certainly worth it.