Bluesky app fork with some witchin' additions 馃挮
at feat/tealfm 25 lines 519 B view raw
1export interface AccumulateResponse<T> { 2 cursor?: string 3 items: T[] 4} 5 6export type AccumulateFetchFn<T> = ( 7 cursor: string | undefined, 8) => Promise<AccumulateResponse<T>> 9 10export async function accumulate<T>( 11 fn: AccumulateFetchFn<T>, 12 pageLimit = 100, 13): Promise<T[]> { 14 let cursor: string | undefined 15 let acc: T[] = [] 16 for (let i = 0; i < pageLimit; i++) { 17 const res = await fn(cursor) 18 cursor = res.cursor 19 acc = acc.concat(res.items) 20 if (!cursor) { 21 break 22 } 23 } 24 return acc 25}