2
2
// Licensed under the MIT License.
3
3
4
4
import { injectable } from 'inversify' ;
5
+ import { createDeferred , Deferred } from '../../common/utils/async' ;
5
6
import { createWorkerPool , IWorkerPool , QueuePosition } from '../../common/utils/workerPool' ;
6
7
import { PythonEnvInfo } from '../base/info' ;
7
8
import { getInterpreterInfo } from '../base/info/interpreter' ;
@@ -44,7 +45,7 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
44
45
// path again and again in a given session. This information will likely not change in a given
45
46
// session. There are definitely cases where this will change. But a simple reload should address
46
47
// those.
47
- private readonly cache : Map < string , PythonEnvInfo > = new Map < string , PythonEnvInfo > ( ) ;
48
+ private readonly cache : Map < string , Deferred < PythonEnvInfo > > = new Map < string , Deferred < PythonEnvInfo > > ( ) ;
48
49
49
50
private readonly workerPool : IWorkerPool < PythonEnvInfo , PythonEnvInfo | undefined > ;
50
51
@@ -59,15 +60,19 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
59
60
const interpreterPath = environment . executable . filename ;
60
61
const result = this . cache . get ( interpreterPath ) ;
61
62
if ( result !== undefined ) {
62
- return result ;
63
+ // Another call for this environment has already been made, return its result
64
+ return result . promise ;
63
65
}
64
-
66
+ const deferred = createDeferred < PythonEnvInfo > ( ) ;
67
+ this . cache . set ( interpreterPath , deferred ) ;
65
68
return ( priority === EnvironmentInfoServiceQueuePriority . High
66
69
? this . workerPool . addToQueue ( environment , QueuePosition . Front )
67
70
: this . workerPool . addToQueue ( environment , QueuePosition . Back )
68
71
) . then ( ( r ) => {
69
72
if ( r !== undefined ) {
70
- this . cache . set ( interpreterPath , r ) ;
73
+ deferred . resolve ( r ) ;
74
+ } else {
75
+ this . cache . delete ( interpreterPath ) ;
71
76
}
72
77
return r ;
73
78
} ) ;
0 commit comments