Skip to content

Commit

Permalink
Handle iterator.onUpdated in ComponentAdapter.getInterpreters().
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Sep 16, 2020
1 parent 4271fd4 commit c04c6f5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/client/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { injectable } from 'inversify';
import * as vscode from 'vscode';
import { createDeferred } from '../common/utils/async';
import { Architecture } from '../common/utils/platform';
import { getVersionString, parseVersion } from '../common/utils/version';
import {
Expand Down Expand Up @@ -293,14 +294,39 @@ class ComponentAdapter implements IComponentAdapter {
}
}

const deferred = createDeferred<PythonEnvironment[]>();
const envs: PythonEnvironment[] = [];
const executableToLegacy: Record<string, PythonEnvironment> = {};
const iterator = this.api.iterEnvs(query);

if (iterator.onUpdated !== undefined) {
iterator.onUpdated((event) => {
if (event === null) {
deferred.resolve(envs);
} else {
// Replace the old one.
const old = executableToLegacy[event.old.executable.filename];
if (old !== undefined) {
const index = envs.indexOf(old);
if (index !== -1) {
envs[index] = convertEnvInfo(event.new);
}
}
}
});
} else {
deferred.resolve(envs);
}

let res = await iterator.next();
while (!res.done) {
envs.push(convertEnvInfo(res.value));
const env = convertEnvInfo(res.value);
envs.push(env);
executableToLegacy[env.path] = env;
res = await iterator.next(); // eslint-disable-line no-await-in-loop
}
return envs;

return deferred.promise;
}
}

Expand Down

0 comments on commit c04c6f5

Please sign in to comment.