From 1599154c2a1993732f2054f789b390aa8e692858 Mon Sep 17 00:00:00 2001 From: Sanjaiyan Parthipan Date: Wed, 13 Dec 2023 13:28:34 +0530 Subject: [PATCH] perf: run function in parallel --- js/src/contents_utils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/src/contents_utils.ts b/js/src/contents_utils.ts index a4bc94f..f78653d 100644 --- a/js/src/contents_utils.ts +++ b/js/src/contents_utils.ts @@ -50,11 +50,13 @@ async function* walkPath(path: string[], root: Content */ export async function revealPath(contents: ContentsModel, path: string[]): Promise> { let node: Content; + let promises: Promise[] = []; for await (node of walkPath(path, contents.root)) { if (!node.isExpand && node.hasChildren) { - await node.expand(); + promises.push(node.expand()); } } + await Promise.all(promises); return node!; } @@ -83,11 +85,13 @@ export async function revealAndSelectPath(contents: Conte * @param path Array of directory names to be opened in order */ export async function openDirRecursive(model: ContentsModel, path: string[]) { + let promises: Promise[] = []; for await (const node of walkPath(path, model.root)) { if (node.pathstr !== model.root.pathstr) { - await model.openDir(node.row); + promises.push(model.openDir(node.row)); } } + await Promise.all(promises); }