Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Asynchronous Recursive Generator
async function* webservice(entity, index = 1) {
const response = await fetch(`${entity}/${index}`);
if (response.ok) {
yield response.json();
yield* webservice(entity, index + 1);
for await (const user of webservice("users")) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment