-
Notifications
You must be signed in to change notification settings - Fork 33
Error handling questions #170
Comments
the methods in this spec are built kind of like this:
so the errors for the arguments are immediate, and the errors during iteration are handled more or less like a normal generator would do |
That sounds right for sync methods; but I’d expect the async methods to never throw synchronously. |
async generators don't return a promise to the generator instance, they return the instance. there's not really a chance to reject anything there. |
Awesome, then they should throw on bad arguments too :-) |
@devsnek correct, so can you confirm they should throw synchronously on bad arguments rather than put the generator in a state where consuming it (.next) throws the error for the argument? |
that matches my interpretation of the current spec |
Great thanks. |
Bug to fix in Node for future reference: nodejs/node#41648 |
When an error happens, it won't call |
@Jack-Works That seems correct. Consider the analogy of for (let item of iterable) {
throw 0;
} that will call |
@bakkot I think function *g() {
yield *iter
} And I think people would expect Anyway, it seems the subset of the passing protocol issue #122 . |
@hax Because of how Right now nothing in the spec invokes I don't think you should think of |
I agree, the way I see it When you have function* naturals() {
for(let i = 0; i < Infinity; i++) yield i;
}
naturals().map(x => { throw new Error(); }).toArray(); In the example - did In practice - I think |
But yeah, |
@bakkot the history was when Jafar worked on the protocol there was an attempt to make it "dual" to observables for that proposal (now dead and changed) and compositional functions (also dead). Consider an alternate universe where:
In this alternate timeline it is important that generators can communicate Honestly it is one of those cases I'm happy we didn't go that route since it was quite confusing. In any case - Python did not play a part afaik. As for why |
Hey a few questions to make sure:
.map(fn)
throws, the error propagates to the consumer, right? (i.e..next
returns a rejected promise and the iterator is closed)..map(1)
throw synchronously or when the generator is first used?)The text was updated successfully, but these errors were encountered: