Skip to content

Commit

Permalink
[WIP]: wait all children.
Browse files Browse the repository at this point in the history
  • Loading branch information
h-sug1no committed Dec 21, 2021
1 parent b54e599 commit 3e4ca4f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tools/generate_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ const appMain = async () => {
pptr_jobs: backendDefs.pptr.jobs,
})
);

const race = async (ps) => {
if (!ps.length) {
return { code: 0 };
}
const { key: doneKey, code } = await Promise.race(ps);
const keyIdx = keys.indexOf(doneKey);
ps.splice(keyIdx, 1);
keys.splice(keyIdx, 1);

return { code };
};

for (const backend in backendDefs) {
if (!exitCode && !backends.none && (backends.all || backends[backend])) {
const { jobs } = backendDefs[backend];
Expand All @@ -192,10 +205,7 @@ const appMain = async () => {
i += 1;
}
if (ps.length) {
const { key: doneKey, code } = await Promise.race(ps);
const keyIdx = keys.indexOf(doneKey);
ps.splice(keyIdx, 1);
keys.splice(keyIdx, 1);
const { code } = await race(ps);
if (code) {
exitCode = code;
log('remote error. aborting...');
Expand All @@ -208,6 +218,14 @@ const appMain = async () => {
// log(`${backend} end`);
}
}

while (ps.length && !exitCode) {
const { code } = await race(ps);
if (code) {
exitCode = code;
}
}

return exitCode;
};

Expand Down

0 comments on commit 3e4ca4f

Please sign in to comment.