Hacker News new | ask | show | jobs
by torginus 32 days ago
> it defensively defers execution any time it encounters one

That's a (bad) JS design choice, for example C# doesn't do this. Actually I'm pretty sure even in JS, async/await gets transpiled to state machines, so I think this is easily fixable by shipping a new transpiler implementation that only defers when necessary.

I get your point, but I don't think we should go back to oldschool yield-based iterators to hack around a broken implementation.

1 comments

Yeah it's fixable. Everything I've built is built on top of a Symbol.streamIterator protocol that omits the unnecessary deferrals. The code looks like this: https://github.com/bablr-lang/node-fs/blob/6dabc6916082eb09c...

I would like to see official support for `Symbol.streamIterator` and for the `for await?(item of iter)` syntax which would transpile to code like you see here (or all the way down to regenerator state machines if needed).