- From: Kevin Gibbons <notifications@github.com>
- Date: Tue, 26 Mar 2024 19:30:59 -0700
- To: whatwg/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/webidl/pull/1397/c2021806864@github.com>
`AsyncIterator.from` will accept strings because `Iterator.from` does. But do note that it's specifically a coercion method. For something like `ReadableStream.from`, which is also a coercion method, you may wish to follow that precedent, but I'm not sure you'd want to do so for other async-iterable-taking things. The way `AsyncIterator.from` works is to look up `Symbol.asyncIterator`, and if that fails then fall back to `Symbol.iterator` with the result wrapped the same way `for await` does (modulo some quibbles not relevant here), and if _that_ fails to use the `.next` method directly (which only _iterator_-taking things should do, which is to say, nothing except this specific method and `AsyncIterator.prototype.flatMap`). And since it will not specifically reject strings, and strings have a `Symbol.iterator`, it will accept them, the same way `for await` does. (Sorry the spec for `AsyncIterator.from` is out of date; I'm working through [other parts of the semantics](https://github.com/tc39/proposal-async-iterator-helpers/issues/4) and it doesn't really make sense to get the spec updated until those are sorted. But this question, at least, is settled.) -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/webidl/pull/1397#issuecomment-2021806864 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/webidl/pull/1397/c2021806864@github.com>
Received on Wednesday, 27 March 2024 02:42:14 UTC