3 ms·
A nice use of async generators is when you have an API with paginated results. The generator function keeps track of the current page. This allows you to use
by emadda 3y ago
A nice use of async generators is when you have an API with paginated results.
The generator function keeps track of the current page.
This allows you to use a `for await` loop which is quite concise.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
You can do it without generator functions, but generator functions allows the caller to not have to know about the underlying pagination API.