@@ -28,7 +28,6 @@ import {
2828 createTaskMetrics ,
2929 updateTaskMetrics ,
3030} from "@benchmark/db"
31- import { inChunksOf } from "@benchmark/lib"
3231import { IpcServer , IpcClient } from "@benchmark/ipc"
3332
3433import { __dirname , extensionDevelopmentPath , exercisesPath } from "./paths.js"
@@ -108,25 +107,39 @@ const run = async (toolbox: GluegunToolbox) => {
108107 // })
109108 // })
110109
111- const chunks = inChunksOf ( tasks , 3 )
110+ const maxConcurrency = 3
111+ const runningPromises : Promise < void > [ ] = [ ]
112112
113- for ( const chunk of chunks ) {
114- await Promise . all (
115- chunk . map ( async ( task ) => {
116- if ( task . finishedAt === null ) {
117- await runExercise ( { run, task, server } )
118- }
113+ const processTask = async ( task : Task ) => {
114+ if ( task . finishedAt === null ) {
115+ await runExercise ( { run, task, server } )
116+ }
119117
120- if ( task . passed === null ) {
121- const passed = await runUnitTest ( { task } )
122- await updateTask ( task . id , { passed } )
123- }
124- } ) ,
125- )
118+ if ( task . passed === null ) {
119+ const passed = await runUnitTest ( { task } )
120+ await updateTask ( task . id , { passed } )
121+ }
122+ }
123+
124+ for ( const task of tasks ) {
125+ const taskPromise = processTask ( task )
126+ runningPromises . push ( taskPromise )
126127
127- break
128+ taskPromise . finally ( ( ) => {
129+ const index = runningPromises . indexOf ( taskPromise )
130+
131+ if ( index > - 1 ) {
132+ runningPromises . splice ( index , 1 )
133+ }
134+ } )
135+
136+ if ( runningPromises . length >= maxConcurrency ) {
137+ await Promise . race ( runningPromises )
138+ }
128139 }
129140
141+ await Promise . all ( runningPromises )
142+
130143 const result = await finishRun ( run . id )
131144 console . log ( "[cli#run]" , result )
132145
0 commit comments