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

Cancel Tree.refresh when new root set #11340

Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions packages/core/src/browser/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,15 @@ export class TreeImpl implements Tree {
return this._root;
}

protected toDisposeOnSetRoot = new DisposableCollection();
set root(root: TreeNode | undefined) {
this.toDisposeOnSetRoot.dispose();
const cancelRefresh = new CancellationTokenSource();
this.toDisposeOnSetRoot.push(cancelRefresh);
this.nodes = {};
this._root = root;
this.addNode(root);
this.refresh();
this.refresh(undefined, cancelRefresh.token);
}

get onChanged(): Event<void> {
Expand Down Expand Up @@ -291,7 +295,7 @@ export class TreeImpl implements Tree {
return this.getNode(id);
}

async refresh(raw?: CompositeTreeNode): Promise<CompositeTreeNode | undefined> {
async refresh(raw?: CompositeTreeNode, cancellationToken?: CancellationToken): Promise<CompositeTreeNode | undefined> {
const parent = !raw ? this._root : this.validateNode(raw);
let result: CompositeTreeNode | undefined;
if (CompositeTreeNode.is(parent)) {
Expand All @@ -300,7 +304,9 @@ export class TreeImpl implements Tree {
try {
result = parent;
const children = await this.resolveChildren(parent);
if (cancellationToken?.isCancellationRequested) { return; }
result = await this.setChildren(parent, children);
if (cancellationToken?.isCancellationRequested) { return; }
} finally {
busySource.cancel();
}
Expand Down