@@ -316,6 +316,20 @@ function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
316
316
} ) ;
317
317
}
318
318
319
+ async function runTaskPool ( tasks : Array < ( ) => Promise < void > > , poolLimit : number ) : Promise < void > {
320
+ let currentIndex = 0 ;
321
+
322
+ async function worker ( ) {
323
+ while ( currentIndex < tasks . length ) {
324
+ const index = currentIndex ++ ;
325
+ await tasks [ index ] ( ) ;
326
+ }
327
+ }
328
+
329
+ const workers = new Array ( Math . min ( poolLimit , tasks . length ) ) . fill ( null ) . map ( ( ) => worker ( ) ) ;
330
+ await Promise . all ( workers ) ;
331
+ }
332
+
319
333
async function regenerate ( flags : RegenerateFlagsInput ) : Promise < void > {
320
334
if ( flags . flavor === undefined ) {
321
335
await regenerate ( { flavor : "azure" , ...flags } ) ;
@@ -331,11 +345,22 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
331
345
const cmdList : TspCommand [ ] = subdirectories . flatMap ( ( subdirectory ) =>
332
346
_getCmdList ( subdirectory , flagsResolved ) ,
333
347
) ;
334
- const PromiseCommands = cmdList . map ( ( tspCommand ) => executeCommand ( tspCommand ) ) ;
335
- await Promise . all ( PromiseCommands ) ;
348
+
349
+ // Create tasks as functions for the pool
350
+ const tasks : Array < ( ) => Promise < void > > = cmdList . map ( ( tspCommand ) => {
351
+ return ( ) => executeCommand ( tspCommand ) ;
352
+ } ) ;
353
+
354
+ // Run tasks with a concurrency limit
355
+ await runTaskPool ( tasks , 30 ) ;
336
356
}
337
357
}
338
358
359
+ const start = performance . now ( ) ;
339
360
regenerate ( argv . values )
340
- . then ( ( ) => console . log ( "Regeneration successful" ) )
361
+ . then ( ( ) =>
362
+ console . log (
363
+ `Regeneration successful, time taken: ${ Math . round ( ( performance . now ( ) - start ) / 1000 ) } s` ,
364
+ ) ,
365
+ )
341
366
. catch ( ( error ) => console . error ( `Regeneration failed: ${ error . message } ` ) ) ;
0 commit comments