Skip to content

Commit

Permalink
Merge pull request #189 from sanjaiyan-dev/sanjaiyan-async-concurrent
Browse files Browse the repository at this point in the history
Move JS revealPath and openDirRecursive to not await row-by-row
  • Loading branch information
timkpaine authored Feb 22, 2025
2 parents 31abc58 + f351a00 commit dc973b3
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 @@ -51,11 +51,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>;
const promises: Array<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 @@ -84,11 +86,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[]) {
const promises: Array<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 dc973b3

Please sign in to comment.