Skip to content

Commit

Permalink
Remove duplicate environment finder event handlers (microsoft#23406)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored and anthonykim1 committed May 16, 2024
1 parent 860c774 commit e21c3c8
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Event, EventEmitter } from 'vscode';
import { Disposable, Event, EventEmitter } from 'vscode';
import { IDisposable } from '../../../../common/types';
import { ILocator, BasicEnvInfo, IPythonEnvsIterator } from '../../locator';
import { PythonEnvsChangedEvent } from '../../watcher';
Expand All @@ -16,6 +16,7 @@ import {
NativeGlobalPythonFinder,
createNativeGlobalPythonFinder,
} from '../common/nativePythonFinder';
import { disposeAll } from '../../../../common/utils/resourceLifecycle';

function categoryToKind(category: string): PythonEnvKind {
switch (category.toLowerCase()) {
Expand Down Expand Up @@ -97,7 +98,11 @@ export class NativeLocator implements ILocator<BasicEnvInfo>, IDisposable {
public iterEnvs(): IPythonEnvsIterator<BasicEnvInfo> {
const promise = this.finder.startSearch();
const envs: BasicEnvInfo[] = [];
this.disposables.push(
const disposables: IDisposable[] = [];
const disposable = new Disposable(() => disposeAll(disposables));
this.disposables.push(disposable);
promise.finally(() => disposable.dispose());
disposables.push(
this.finder.onDidFindPythonEnvironment((data: NativeEnvInfo) => {
envs.push({
kind: categoryToKind(data.category),
Expand Down

0 comments on commit e21c3c8

Please sign in to comment.