修复点位楼层跳转并优化模型加载缓存

This commit is contained in:
lyf
2026-07-02 16:42:38 +08:00
parent 7cda427de9
commit 9b1f855515
8 changed files with 750 additions and 41 deletions

20
src/utils/concurrency.ts Normal file
View File

@@ -0,0 +1,20 @@
export const mapWithConcurrency = async <T, R>(
items: T[],
concurrency: number,
mapper: (item: T, index: number) => Promise<R>
): Promise<R[]> => {
const results: R[] = new Array(items.length)
const limit = Math.max(1, Math.floor(concurrency))
let nextIndex = 0
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
while (nextIndex < items.length) {
const currentIndex = nextIndex
nextIndex += 1
results[currentIndex] = await mapper(items[currentIndex], currentIndex)
}
})
await Promise.all(workers)
return results
}