fix(lib/core.js): remove required @@asyncIterator method from $AsyncIterator#6075
fix(lib/core.js): remove required @@asyncIterator method from $AsyncIterator#6075jedwards1211 wants to merge 1 commit intofacebook:masterfrom
Conversation
…terator AsyncIterators are not required to be AsyncIterables, AFAIK
|
Could you provide some docs (e.g. MDN or the ECMAScript spec) to back up this change? |
|
https://tc39.github.io/proposal-async-iteration/#sec-control-abstraction-objects-patch makes clear that |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@nmote has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
However, confusingly, the docs also state: I don't fully understand this, but I think it means that iterators created by, for instance, calling a generator function, will have an |
|
Ah, good catch. It looks like the same applies to #6076: https://www.ecma-international.org/ecma-262/6.0/#sec-%iteratorprototype%-@@iterator Should these both be closed, then? |
|
@nmote I doubt it, I think |
|
@nmote after all https://www.ecma-international.org/ecma-262/6.0/#sec-iterator-interface doesn't say anything about |
|
MDN explicitly illustrates that the Iterable/Iterator interfaces can but do not have to be mixed: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
|
|
Another example shows an iterator object without a |
|
Okay, I've spent a bit more time digging into this. Let's just centralize the discussion about both PRs here, since they are basically the same conceptually. You are correct that the So, at the very least, if we are to make this change, we should also create something like an My main concern is that even if this change is made, it would still result in significant rollout pain. If you'd like to make it, I can try it out on our internal codebases to get a sense for what that pain would be (as long as you understand that I'm not promising that it will actually land). For an example of the kind of pain I'm talking about, some functions are currently annotated as returning an I'm not opposed in principle to creating a rollout burden, but in this case I see a pretty concrete downside. I don't really see a huge upside to this change. Sure, if I were starting from scratch, I would agree that this is better, but the current behavior isn't unsafe in any way, and I'm not sure it's causing any serious problems. I'm worried that the cost/benefit analysis doesn't work out in favor of making this change. What do you think? |
|
@nmote I see what you mean. Yeah, considering that not many other people seem to be running into this issue, sounds like it's probably not a net benefit to flow users overall. I've only had flow errors from this in a few places myself and it's easy to suppress the errors or just add a It's weird to me that people in the JS world are so apt to mix iterators and iterables. In Java at least, iterables are ideally supposed to always create a fresh iterator -- one that starts from the beginning of the collection or whatever it's iterating -- and an Iterator/Iterable that returns itself would violate this principle since the iterator could be halfway done. I'm not a fan of mixing the two. I guess JS folks decided this start-from-the-beginning behavior of iterables wasn't as important (probably because generator functions do create a start-from-the-beginning Iterator/Iterable each time they're called). |
Agreed, but here we are. 🤷♂️ |
|
@nmote FWIW, TypeScript's They have a separate |
AsyncIterators are not required to be AsyncIterables, AFAIK