Skip to content

Commit d31f823

Browse files
author
Kartik Raj
committed
Modify cache to carry deferred instead
1 parent b3e4222 commit d31f823

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/client/pythonEnvironments/info/environmentInfoService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { injectable } from 'inversify';
5+
import { createDeferred, Deferred } from '../../common/utils/async';
56
import { createWorkerPool, IWorkerPool, QueuePosition } from '../../common/utils/workerPool';
67
import { PythonEnvInfo } from '../base/info';
78
import { getInterpreterInfo } from '../base/info/interpreter';
@@ -44,7 +45,7 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
4445
// path again and again in a given session. This information will likely not change in a given
4546
// session. There are definitely cases where this will change. But a simple reload should address
4647
// 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>>();
4849

4950
private readonly workerPool: IWorkerPool<PythonEnvInfo, PythonEnvInfo | undefined>;
5051

@@ -59,15 +60,19 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
5960
const interpreterPath = environment.executable.filename;
6061
const result = this.cache.get(interpreterPath);
6162
if (result !== undefined) {
62-
return result;
63+
// Another call for this environment has already been made, return its result
64+
return result.promise;
6365
}
64-
66+
const deferred = createDeferred<PythonEnvInfo>();
67+
this.cache.set(interpreterPath, deferred);
6568
return (priority === EnvironmentInfoServiceQueuePriority.High
6669
? this.workerPool.addToQueue(environment, QueuePosition.Front)
6770
: this.workerPool.addToQueue(environment, QueuePosition.Back)
6871
).then((r) => {
6972
if (r !== undefined) {
70-
this.cache.set(interpreterPath, r);
73+
deferred.resolve(r);
74+
} else {
75+
this.cache.delete(interpreterPath);
7176
}
7277
return r;
7378
});

0 commit comments

Comments
 (0)