Created
July 20, 2018 23:29
-
-
Save reddyonrails/5b39d40a4753269465644053bf5e937a to your computer and use it in GitHub Desktop.
async_generator.js
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 *getRecords() { | |
const initialResponse = await getRecords(); | |
yield* initialResponse.data; | |
let nextPage = initialResponse.pagination_token; | |
while(nextPage) { | |
const response = await getRecords(nextPage); | |
yield* response.data; | |
nextPage = response.pagination_token; | |
} | |
} | |
for await (const record of getRecords()) { | |
handle(record); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment