Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Awaiting of IteratorValue in %AsyncIteratorPrototype% methods #168

Closed
zloirock opened this issue Jan 5, 2022 · 8 comments
Closed

Awaiting of IteratorValue in %AsyncIteratorPrototype% methods #168

zloirock opened this issue Jan 5, 2022 · 8 comments

Comments

@zloirock
Copy link
Contributor

zloirock commented Jan 5, 2022

See the original issue in the Array.fromAsync proposal. The same is applicable to %AsyncIteratorPrototype% methods.

const i = 0;

await AsyncIterator.from(it = {
  [Symbol.asyncIterator]() {
    return {
      async next() {
        if (i > 2) return { done: true };
        i++;
        return { value: Promise.resolve(i), done: false }
      }
    }
  }
}).toArray(); // => ???

I think that it should be agreed upon between both proposals.

@ljharb
Copy link
Member

ljharb commented Jan 5, 2022

Async iterator helpers should be awaiting the value too, I’d expect.

@benjamingr
Copy link
Contributor

I would expect the behavior to be the same as async iterators in `for await. That is, tc39/proposal-async-iteration#15 (unfortunately, I don't particularly like this behaviour).

@bakkot
Copy link
Collaborator

bakkot commented Jul 6, 2022

I agree with the OP that they should match. I like the behavior currently in this proposal, which is what you'd get with for await, which would result in the code in the OP resulting in an array containing three promises.

@michaelficarra
Copy link
Member

Closing as nothing to do here.

@zloirock
Copy link
Contributor Author

zloirock commented Jul 8, 2022

@michaelficarra why? It's still not aligned between both proposals and the inconsistency should be resolved.

@michaelficarra
Copy link
Member

@zloirock The inconsistency can be resolved by this proposal remaining unchanged and the Array.fromAsync proposal changing. So nothing to do here.

@zloirock
Copy link
Contributor Author

zloirock commented Jul 8, 2022

@michaelficarra as you can see, they (at least @ljharb and @js-choi) decided to change the behavior that's used here. So, please, instead of ignoring this issue, align it - I don't care on what side. I'm (and it seems all the rest) pretty sure that those methods should use one approach.

@js-choi
Copy link

js-choi commented Jul 10, 2022

For what it’s worth, I’ve come around to the old behavior of Array.fromAsync, which matches the iterator-helpers spec. See tc39/proposal-array-from-async#19 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants