Created
July 20, 2018 23:29
async_generator.js
This file contains hidden or 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