Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Calling return or throw on paused async generator #5

Closed
zenparsing opened this issue Feb 21, 2015 · 4 comments
Closed

Calling return or throw on paused async generator #5

zenparsing opened this issue Feb 21, 2015 · 4 comments

Comments

@zenparsing
Copy link
Member

Consider:

async function* agf() {
    try { await new Promise(_=> null) }
    catch (x) { print("caught error") }
    finally { print("finally!") }
}

var ag = agf();
ag.next();
ag.return();

What should happen in this case? The generator is waiting infinitely on a never-resolved promise. Should "return" and "throw" resume the generator even though it is paused on an await? It seems like it should.

@zenparsing zenparsing changed the title Calling next, return, or throw on paused async generator Calling return or throw on paused async generator Feb 21, 2015
@zenparsing
Copy link
Member Author

If the answer is yes, then that means that we cannot queue continuation requests for next, throw, and return. We would instead have to reject any attempt to resume the generator when there is a current request in flight.

@zenparsing
Copy link
Member Author

I think the answer must be no, at least for "throw". If we have:

try { await somethingAsync() }
catch (x) { }

Then we must be able to assume that x arose as a result of the evaluation of somethingAsync(), and nothing else.

That leaves "return"...

@domenic
Copy link
Member

domenic commented Feb 24, 2015

I agree the answer should be no in both cases.

I think both next() and throw() should return promises that are pending forever, to signal that they never get a chance to execute.

@jedwards1211
Copy link

jedwards1211 commented Dec 24, 2019

@domenic in light of #126 I don't get this. I don't see anything in the spec for return and throw that says they must resolve or reject after all promises returned by prior calls to next?

To me it would be more reasonable if we add a clarification to the async iterator protocol that pending promises from next should reject when return or throw is called. This would solve a lot or problems with cleanup -- would it cause any new problems?

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

3 participants