I needed a way to receive the successive results of concurrent promises under the form of an async generator, so I coded a small reusable function that does the trick. Since my understanding of promises and async generators is not perfect, my question is: is there a more idiomatic way of doing this ?
It uses the stdlib ‘Generators.queue’ method, but this makes the code quite a bit more compact, and saves you Map and book-keeping: https://beta.observablehq.com/d/11b5e6f34cde7600 . Also, Promises.delay already takes a second argument for the resolved value, so the additional method is unnecessary.
Thanks for the reply Tom, but I can’t access your notebook (may be it isn’t shared ?). In the meantime I’ll take a look at the doc for Generators.queue()
Whoops! Should be visible now.
OK I got it right : this is exactly the new implementation I coded after visiting the doc. But such a generator doesn’t know how to terminate, or am I missing something ? So I modified my notebook and coded a version that also wraps Generator.queue(), but counts resolved promises to know when to terminate. Is it the right way to do that ?