build: parallelize multi package builds
This commit is contained in:
parent
df48fc225a
commit
3016b811b8
@ -50,9 +50,25 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function buildAll(targets) {
|
async function buildAll(targets) {
|
||||||
for (const target of targets) {
|
await runParallel(require('os').cpus().length, targets, build)
|
||||||
await build(target)
|
}
|
||||||
|
|
||||||
|
async function runParallel(maxConcurrency, source, iteratorFn) {
|
||||||
|
const ret = []
|
||||||
|
const executing = []
|
||||||
|
for (const item of source) {
|
||||||
|
const p = Promise.resolve().then(() => iteratorFn(item, source))
|
||||||
|
ret.push(p)
|
||||||
|
|
||||||
|
if (maxConcurrency <= source.length) {
|
||||||
|
const e = p.then(() => executing.splice(executing.indexOf(e), 1))
|
||||||
|
executing.push(e)
|
||||||
|
if (executing.length >= maxConcurrency) {
|
||||||
|
await Promise.race(executing)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return Promise.all(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function build(target) {
|
async function build(target) {
|
||||||
|
Loading…
Reference in New Issue
Block a user