Skip to content

Instantly share code, notes, and snippets.

@reddyonrails
Created July 20, 2018 23:29
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