Skip to content

Commit

Permalink
perf: run function in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaiyan-dev authored Dec 13, 2023
1 parent e7ea3ce commit 1599154
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/src/contents_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ async function* walkPath<T extends IContentRow>(path: string[], root: Content<T>
*/
export async function revealPath<T extends IContentRow>(contents: ContentsModel<T>, path: string[]): Promise<Content<T>> {
let node: Content<T>;
let promises: Promise<void>[] = [];
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!;
}

Expand Down Expand Up @@ -83,11 +85,13 @@ export async function revealAndSelectPath<T extends IContentRow>(contents: Conte
* @param path Array of directory names to be opened in order
*/
export async function openDirRecursive<T extends IContentRow>(model: ContentsModel<T>, path: string[]) {
let promises: Promise<void>[] = [];
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);
}


Expand Down

0 comments on commit 1599154

Please sign in to comment.