Files
orca/src/shared/map-with-concurrency.ts
T
Jinjing a916a93df3 Make explicit desktop take-back always release the mobile presence lock (#8200)
Previously a failed resize during reclaimTerminalForDesktop left the
override/lock in place (#7588 semantics), but for an explicit "take
back all terminals" gesture that could strand banners on background
panes whose resize can't converge. Now the take-back unconditionally
releases the driver and clears any held fit-override via a new
releaseDesktopTakeBack helper, while auto-restore and phone-initiated
paths keep the original keep-lock-on-failure behavior.

Also extract the local mapWithConcurrency helper out of
workspace-cleanup.ts into a shared, tested src/shared/map-with-concurrency.ts
and use it to bound concurrent desktop-fit reclaims in
terminal-fit-restore.ts.
2026-07-10 19:41:27 -07:00

25 lines
906 B
TypeScript

// Why: bounded-concurrency map. `Promise.all(items.map(fn))` fans out every
// item at once — fine for a handful, but a burst of hundreds of concurrent
// IPC/RPC round-trips can swamp the transport or its call queue. This runs at
// most `limit` calls in flight via a fixed worker pool while preserving input
// order in the result array (results[i] corresponds to items[i]).
export async function mapWithConcurrency<T, R>(
items: readonly T[],
limit: number,
fn: (item: T, index: number) => Promise<R>
): Promise<R[]> {
const results: R[] = []
let nextIndex = 0
const workerCount = Math.max(1, Math.min(limit, items.length))
await Promise.all(
Array.from({ length: workerCount }, async () => {
while (nextIndex < items.length) {
const index = nextIndex
nextIndex += 1
results[index] = await fn(items[index], index)
}
})
)
return results
}