Skip to content

Instantly share code, notes, and snippets.

@ViliamKopecky
Created April 10, 2022 09:47
Show Gist options
  • Save ViliamKopecky/c953045553d974e1cd64f3a49ed7302c to your computer and use it in GitHub Desktop.
Save ViliamKopecky/c953045553d974e1cd64f3a49ed7302c to your computer and use it in GitHub Desktop.
loading paginated async data
export async function loadPaginated<R>(loader: (page: number) => Promise<R[]>) {
const results: R[] = []
while (true) {
const found = await loader(i)
results.push(...found)
if (!found.length) {
break
}
}
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment