@@ -281,6 +281,20 @@ function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
281281 } ) ;
282282}
283283
284+ async function runTaskPool ( tasks : Array < ( ) => Promise < void > > , poolLimit : number ) : Promise < void > {
285+ let currentIndex = 0 ;
286+
287+ async function worker ( ) {
288+ while ( currentIndex < tasks . length ) {
289+ const index = currentIndex ++ ;
290+ await tasks [ index ] ( ) ;
291+ }
292+ }
293+
294+ const workers = new Array ( Math . min ( poolLimit , tasks . length ) ) . fill ( null ) . map ( ( ) => worker ( ) ) ;
295+ await Promise . all ( workers ) ;
296+ }
297+
284298async function regenerate ( flags : RegenerateFlagsInput ) : Promise < void > {
285299 if ( flags . flavor === undefined ) {
286300 await regenerate ( { ...flags , flavor : "azure" } ) ;
@@ -296,8 +310,14 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
296310 const cmdList : TspCommand [ ] = subdirectories . flatMap ( ( subdirectory ) =>
297311 _getCmdList ( subdirectory , flagsResolved ) ,
298312 ) ;
299- const PromiseCommands = cmdList . map ( ( tspCommand ) => executeCommand ( tspCommand ) ) ;
300- await Promise . all ( PromiseCommands ) ;
313+
314+ // Create tasks as functions for the pool
315+ const tasks : Array < ( ) => Promise < void > > = cmdList . map ( ( tspCommand ) => {
316+ return ( ) => executeCommand ( tspCommand ) ;
317+ } ) ;
318+
319+ // Run tasks with a concurrency limit
320+ await runTaskPool ( tasks , 30 ) ;
301321 }
302322}
303323
@@ -319,6 +339,7 @@ const argv = yargs(hideBin(process.argv))
319339 description : "Specify filename if you only want to generate a subset" ,
320340 } ) . argv ;
321341
342+ const start = performance . now ( ) ;
322343regenerate ( argv as RegenerateFlags )
323- . then ( ( ) => console . log ( " Regeneration successful" ) )
344+ . then ( ( ) => console . log ( ` Regeneration successful, time taken: ${ Math . round ( ( performance . now ( ) - start ) / 1000 ) } s` ) )
324345 . catch ( ( error ) => console . error ( `Regeneration failed: ${ error . message } ` ) ) ;
0 commit comments