diff --git a/_webi/lint-builds.js b/_webi/lint-builds.js index f74e51d..9a8d703 100644 --- a/_webi/lint-builds.js +++ b/_webi/lint-builds.js @@ -5,6 +5,7 @@ let Fs = require('node:fs/promises'); let Path = require('node:path'); let BuildsCacher = require('./builds-cacher.js'); +let Parallel = require('./parallel.js'); var INSTALLERS_DIR = Path.join(__dirname, '..'); var CACHE_DIR = Path.join(__dirname, '../_cache'); @@ -110,15 +111,17 @@ async function main() { // return triples; // // process.exit(1) - let triples = []; let rows = []; + let triples = []; let valids = Object.keys(dirs.valid); console.info(`Fetching builds for`); - for (let name of valids) { + let limit = 25; + //let limit = 1; + await Parallel.run(limit, valids, async function (name, i) { if (name === 'webi') { // TODO fix the webi faux package // (not sure why I even created it) - continue; + return; } console.info(` ${name}`); @@ -152,9 +155,9 @@ async function main() { } triples.push(triplet); - rows.push(`${triplet}\t${name}\t${build.version}`); + rows.push(`${triplet}\t${pkg.name}\t${build.version}`); } - } + }); let tsv = rows.join('\n'); console.info(''); console.info('#rows', rows.length); diff --git a/_webi/parallel.js b/_webi/parallel.js new file mode 100644 index 0000000..08d9f89 --- /dev/null +++ b/_webi/parallel.js @@ -0,0 +1,44 @@ +'use strict'; + +var Parallel = module.exports; +Parallel.run = async function (limit, arr, fn) { + let index = 0; + let actives = []; + let results = []; + limit = Math.min(limit, arr.length); + + function launch() { + let _index = index; + let p = fn(arr[_index], _index, arr); + + // some tasks may be synchronous + // so we must push before removing + actives.push(p); + + p.then(function _resolve(result) { + let i = actives.indexOf(p); + actives.splice(i, 1); + results[_index] = result; + }); + + index += 1; + } + + // start tasks in parallel, up to limit + for (; actives.length < limit; ) { + launch(); + } + + // keep the task queue full + for (; index < arr.length; ) { + // wait for one task to complete + await Promise.race(actives); + // add one task again + launch(); + } + + // wait for all remaining tasks + await Promise.all(actives); + + return results; +};