@@ -37,21 +37,15 @@ const createGenerator = input => {
3737 *
3838 * @param {GeneratorOptions } options The options for the generator runtime
3939 */
40- const runGenerators = async ( {
41- generators,
42- threads,
43- chunkSize,
44- ...extra
45- } ) => {
40+ const runGenerators = async options => {
41+ const { generators, threads } = options ;
42+
4643 // WorkerPool for running full generators in worker threads
4744 const generatorPool = new WorkerPool ( './generator-worker.mjs' , threads ) ;
4845
4946 // WorkerPool for chunk-level parallelization within generators
5047 const chunkPool = new WorkerPool ( './chunk-worker.mjs' , threads ) ;
5148
52- // Options including threading config
53- const threadingOptions = { threads, chunkSize } ;
54-
5549 // Note that this method is blocking, and will only execute one generator per-time
5650 // but it ensures all dependencies are resolved, and that multiple bottom-level generators
5751 // can reuse the already parsed content from the top-level/dependency generators
@@ -61,34 +55,21 @@ const createGenerator = input => {
6155 // If the generator dependency has not yet been resolved, we resolve
6256 // the dependency first before running the current generator
6357 if ( dependsOn && dependsOn in cachedGenerators === false ) {
64- await runGenerators ( {
65- ...extra ,
66- ...threadingOptions ,
67- generators : [ dependsOn ] ,
68- } ) ;
58+ await runGenerators ( { ...options , generators : [ dependsOn ] } ) ;
6959 }
7060
7161 // Ensures that the dependency output gets resolved before we run the current
7262 // generator with its dependency output as the input
7363 const input = await cachedGenerators [ dependsOn ] ;
7464
7565 // Create a ParallelWorker for this generator to use for item-level parallelization
76- const worker = createParallelWorker ( generatorName , chunkPool , {
77- ...extra ,
78- ...threadingOptions ,
79- } ) ;
80-
81- // Generator options with worker instance
82- const generatorOptions = { ...extra , ...threadingOptions , worker } ;
83-
84- // Worker options for the worker thread
85- const workerOptions = { ...extra , ...threadingOptions } ;
66+ const worker = createParallelWorker ( generatorName , chunkPool , options ) ;
8667
8768 // Adds the current generator execution Promise to the cache
8869 cachedGenerators [ generatorName ] =
8970 threads < 2
90- ? generate ( input , generatorOptions ) // Run in main thread
91- : generatorPool . run ( { generatorName, input, options : workerOptions } ) ; // Offload to worker thread
71+ ? generate ( input , { ... options , worker } )
72+ : generatorPool . run ( { generatorName, input, options } ) ;
9273 }
9374
9475 // Returns the value of the last generator of the current pipeline
0 commit comments