9d22cb61c7
Cache plaintext list metadata on entry save so the journal list avoids full decrypt per row, and batch sync pull writes with main-thread yields. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
672 B
TypeScript
25 lines
672 B
TypeScript
/** Yield so long tasks can interleave with paint and input handling. */
|
|
export function yieldToMain(): Promise<void> {
|
|
return new Promise((resolve) => {
|
|
setTimeout(resolve, 0)
|
|
})
|
|
}
|
|
|
|
/** Run an async handler over items in batches, yielding between batches. */
|
|
export async function forEachInBatches<T>(
|
|
items: T[],
|
|
batchSize: number,
|
|
handler: (item: T) => Promise<void>
|
|
): Promise<void> {
|
|
if (items.length === 0) return
|
|
const size = Math.max(1, batchSize)
|
|
|
|
for (let i = 0; i < items.length; i += size) {
|
|
if (i > 0) await yieldToMain()
|
|
const batch = items.slice(i, i + size)
|
|
for (const item of batch) {
|
|
await handler(item)
|
|
}
|
|
}
|
|
}
|