Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/nperez0111/bookhive. Track your books, share your shelves, see what others are reading bookhive.buzz
atproto bluesky books bookshelf goodreads management-system
Something went wrong. Try again.
TypeScript
1234567891011121314151617181920212223242526272829303132333435export function createBatchTransform<T, R>( batchSize: number, processBatch: (items: T[]) => Promise<R>, onBatchComplete?: (processedCount: number) => void,): TransformStream<T, R> { let batch: T[] = []; let totalProcessed = 0;
return new TransformStream<T, R>({ transform(item, controller) { batch.push(item);
if (batch.length >= batchSize) { return processBatch(batch).then((result) => { controller.enqueue(result); totalProcessed += batch.length; onBatchComplete?.(totalProcessed); batch = []; }); } },
flush(controller) { if (batch.length > 0) { return processBatch(batch).then((result) => { controller.enqueue(result); totalProcessed += batch.length; onBatchComplete?.(totalProcessed); batch = []; }); } }, });}