Last active
December 17, 2021 15:15
-
-
Save aminnairi/36fd4447dcf65125c68e95edb8c20470 to your computer and use it in GitHub Desktop.
Asynchronous Recursive Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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