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' ;
55import { IDisposable } from '../../../../common/types' ;
66import { ILocator , BasicEnvInfo , IPythonEnvsIterator } from '../../locator' ;
77import { PythonEnvsChangedEvent } from '../../watcher' ;
@@ -16,6 +16,7 @@ import {
1616 NativeGlobalPythonFinder ,
1717 createNativeGlobalPythonFinder ,
1818} from '../common/nativePythonFinder' ;
19+ import { disposeAll } from '../../../../common/utils/resourceLifecycle' ;
1920
2021function 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