Skip to content

Instantly share code, notes, and snippets.

@aminnairi
Last active December 17, 2021 15:15
Show Gist options
  • Save aminnairi/36fd4447dcf65125c68e95edb8c20470 to your computer and use it in GitHub Desktop.
Save aminnairi/36fd4447dcf65125c68e95edb8c20470 to your computer and use it in GitHub Desktop.
Asynchronous Recursive Generator
async function* webservice(entity, index = 1) {
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`);
if (response.ok) {
yield response.json();
yield* webservice(entity, index + 1);
}
}
for await (const user of webservice("users")) {
console.log(user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment