1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { Event , EventEmitter } from 'vscode' ;
4
+ import { Disposable , Event , EventEmitter } from 'vscode' ;
5
5
import { IDisposable } from '../../../../common/types' ;
6
6
import { ILocator , BasicEnvInfo , IPythonEnvsIterator } from '../../locator' ;
7
7
import { PythonEnvsChangedEvent } from '../../watcher' ;
@@ -16,6 +16,7 @@ import {
16
16
NativeGlobalPythonFinder ,
17
17
createNativeGlobalPythonFinder ,
18
18
} from '../common/nativePythonFinder' ;
19
+ import { disposeAll } from '../../../../common/utils/resourceLifecycle' ;
19
20
20
21
function categoryToKind ( category : string ) : PythonEnvKind {
21
22
switch ( category . toLowerCase ( ) ) {
@@ -97,7 +98,11 @@ export class NativeLocator implements ILocator<BasicEnvInfo>, IDisposable {
97
98
public iterEnvs ( ) : IPythonEnvsIterator < BasicEnvInfo > {
98
99
const promise = this . finder . startSearch ( ) ;
99
100
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 (
101
106
this . finder . onDidFindPythonEnvironment ( ( data : NativeEnvInfo ) => {
102
107
envs . push ( {
103
108
kind : categoryToKind ( data . category ) ,
0 commit comments