MCPcopy Index your code
hub / github.com/simstudioai/sim / acquireWorker

Function acquireWorker

apps/sim/lib/execution/isolated-vm.ts:1060–1076  ·  view source on GitHub ↗

* Tries to get an existing worker with capacity, or spawns a new one if the * pool is not full. Returns null when the pool is at capacity and all workers * are saturated (caller should enqueue).

()

Source from the content-addressed store, hash-verified

1058 * are saturated (caller should enqueue).
1059 */
1060async function acquireWorker(): Promise<WorkerInfo | null> {
1061 const existing = selectWorker()
1062 if (existing) return existing
1063
1064 const activeWorkerCount = [...workers.values()].filter((w) => !w.retiring).length
1065 const currentPoolSize = activeWorkerCount + spawnInProgress
1066 if (currentPoolSize < POOL_SIZE) {
1067 try {
1068 return await spawnWorker()
1069 } catch (error) {
1070 logger.error('Failed to spawn worker', { error })
1071 return null
1072 }
1073 }
1074
1075 return null
1076}
1077
1078function dispatchToWorker(
1079 workerInfo: WorkerInfo,

Callers 1

executeInIsolatedVMFunction · 0.85

Calls 3

selectWorkerFunction · 0.85
spawnWorkerFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected