Skip to content

Instantly share code, notes, and snippets.

@reddyonrails
Created July 20, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reddyonrails/5b39d40a4753269465644053bf5e937a to your computer and use it in GitHub Desktop.
Save reddyonrails/5b39d40a4753269465644053bf5e937a to your computer and use it in GitHub Desktop.
async_generator.js
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