-
Notifications
You must be signed in to change notification settings - Fork 44
Is the AsyncGeneratorQueue really necessary? #55
Comments
Yes, there are many cases where you want to get promises for multiple values at once, e.g. to Promise.all them. Going to close this since this kind of fundamental design change is not in the cards for stage 3, but happy to continue discussion in the closed issue. |
Being able to use |
As a simple example, let's say you know by contract that the API will always return at least two values or error along the way (i.e. it will never return 1 value then exit). Then: const [{ value }, { value }] = await Promise.all([ag.next(), ag.next()]); |
@rauschma Another practical example might be when you're using an async generator as a sink (e.g. when writing to a file). In that case, you might want to A contrived example: writer.next(bufferA);
writer.next(bufferB);
await writer.return(); // Only wait for the file to close More abstractly, if we made the generator reject when a |
@domenic: that makes sense, thanks! @zenparsing: interesting example! I’d probably want access to the queue then, to configure how it works. I like how CSP handles this: http://jlongster.com/Taming-the-Asynchronous-Beast-with-CSP-in-JavaScript |
After receiving a promise from
next()
, would it ever make sense to callnext()
again before that promise is settled? After all,done
tells you whether you should continue iterating or not.If not then one could simply throw an error if
next()
is called before the previously returned promise is settled and no queue would be needed.The text was updated successfully, but these errors were encountered: