Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing Performance and Resource Efficiency with Promise.all ✈️ #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading