/** 限并发执行,避免批量操作一次打出几十个请求 */ export async function runWithConcurrency( items: T[], limit: number, worker: (item: T, index: number) => Promise, ) { let cursor = 0 const runners = Array.from({ length: Math.min(limit, items.length) }, async () => { while (cursor < items.length) { const index = cursor cursor += 1 await worker(items[index], index) } }) await Promise.all(runners) }