Skip to content

Commit

Permalink
Parallel loading
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed May 2, 2024
1 parent 5e3a159 commit fb8f587
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions util/packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,11 @@ export async function read() {
const files = (await readdir(directory, {recursive: true}))
.filter(s => /^([^.][^/]*\/)*[^.][^/]*\.json$/.test(s))
.sort(comparePaths);

const packages = [];
for (const file of files) {
const filePath = pathJoin(directory, file);

// eslint-disable-next-line no-await-in-loop
const code = await readFile(filePath, 'utf8');
const doc = JSON.parse(code);
packages.push(...doc);
}

return packages;
return (
await Promise.all(
files.map(async f =>
JSON.parse(await readFile(pathJoin(directory, f), 'utf8'))
)
)
).flat(1);
}

0 comments on commit fb8f587

Please sign in to comment.