Comment

Comment by gchq-7703

I don't believe that's true. Consider this infinite generator:

    async function* infinite() {
      while (1) {
        yield 'example'
      }
    }

    (async function () {
      for await (const value of infinite()) {
        console.log(value)
      }
    })()
If the generator was consumed all at once, this would never print (because the generator is infinite). `for await... of` should only consume a single step of the stream / generator at a time. It's just syntactic sugar for the usual calls to .next() and etc. See the docs here[0]

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

parent gchq-7703 3 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton