Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

will it always close sync iterators? #39

Closed
vadzim opened this issue Mar 2, 2023 · 2 comments
Closed

will it always close sync iterators? #39

vadzim opened this issue Mar 2, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@vadzim
Copy link

vadzim commented Mar 2, 2023

for await is known to not close sync iterables if rejected promise is emited.
Like

function* It() {
  try {
    yield Promise.resolve("a")
    yield Promise.reject("b")
  } finally {
    console.log("finalized")
  }
}

// prints "a" and never prints "finalized"
for await (const x of It()) { console.log(x) }

// prints "a" and then prints "finalized"
for (const x of It()) { console.log(await x) }

which of theses behaviors will implement Array.fromAsync?

@mgaudet
Copy link

mgaudet commented Mar 29, 2023

As implemented, we have the same semantics as for await (const x of It()) ..., and so the iterable is not closed.

@bakkot
Copy link
Contributor

bakkot commented Apr 27, 2023

@mgaudet There's actually been consensus to change the behavior for for await over sync iterators so that it closes them for... over a year now, I guess; it's blocked on lack of tests. Since this proposal uses the same machinery it will be affected as well.

@js-choi js-choi added the documentation Improvements or additions to documentation label Dec 2, 2023
@js-choi js-choi closed this as completed in 52a4684 Dec 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants