Skip to content

Commit 424ca3f

Browse files
committed
Remove duplicate environment finder event handlers (#23406)
1 parent 97ff7d5 commit 424ca3f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/client/pythonEnvironments/base/locators/lowLevel/nativeLocator.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { Event, EventEmitter } from 'vscode';
4+
import { Disposable, Event, EventEmitter } from 'vscode';
55
import { IDisposable } from '../../../../common/types';
66
import { ILocator, BasicEnvInfo, IPythonEnvsIterator } from '../../locator';
77
import { PythonEnvsChangedEvent } from '../../watcher';
@@ -16,6 +16,7 @@ import {
1616
NativeGlobalPythonFinder,
1717
createNativeGlobalPythonFinder,
1818
} from '../common/nativePythonFinder';
19+
import { disposeAll } from '../../../../common/utils/resourceLifecycle';
1920

2021
function categoryToKind(category: string): PythonEnvKind {
2122
switch (category.toLowerCase()) {
@@ -97,7 +98,11 @@ export class NativeLocator implements ILocator<BasicEnvInfo>, IDisposable {
9798
public iterEnvs(): IPythonEnvsIterator<BasicEnvInfo> {
9899
const promise = this.finder.startSearch();
99100
const envs: BasicEnvInfo[] = [];
100-
this.disposables.push(
101+
const disposables: IDisposable[] = [];
102+
const disposable = new Disposable(() => disposeAll(disposables));
103+
this.disposables.push(disposable);
104+
promise.finally(() => disposable.dispose());
105+
disposables.push(
101106
this.finder.onDidFindPythonEnvironment((data: NativeEnvInfo) => {
102107
envs.push({
103108
kind: categoryToKind(data.category),

0 commit comments

Comments
 (0)