Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Sep 15, 2023
1 parent 929fd7e commit 4095967
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable no-restricted-globals */
import { parentPort, workerData } from 'worker_threads';
Expand All @@ -18,11 +19,12 @@ parentPort.on('message', async (event) => {
if (!parentPort) {
throw new Error('Not in a worker thread');
}
const { methodName, args } = event;
type EventType = { methodName: string; args: any[] };
const { methodName, args } = event as EventType;
if (methodName && typeof envsMiddleware[methodName as keyof EnvsMiddleWare] === 'function') {
const method = envsMiddleware[methodName as keyof EnvsMiddleWare] as Function;
try {
const result = await method.apply(envsMiddleware, ...args);
const result = await method.apply(envsMiddleware, args);
parentPort.postMessage({ methodName, result });
} catch (error) {
parentPort.postMessage({ methodName, error: (error as Error).message });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, EventEmitter, WorkspaceFoldersChangeEvent, workspace } from 'vscode';
import { Event, EventEmitter, WorkspaceFolder, WorkspaceFoldersChangeEvent, workspace } from 'vscode';
import * as path from 'path';
import { Worker } from 'worker_threads';
import { PythonEnvInfo } from '../../info';
Expand All @@ -19,9 +19,9 @@ export class WorkerThreadMiddleWare extends PythonEnvsWatcher implements IWorker

private onUpdatedMap = new Map<EnvIteratorId, Event<PythonEnvUpdatedEvent | ProgressNotificationEvent>>();

constructor() {
constructor(folders: readonly WorkspaceFolder[] | undefined) {
super();
this.worker = new Worker(path.join(__dirname, 'worker.js'), { workerData: workspace.workspaceFolders });
this.worker = new Worker(path.join(__dirname, 'worker.js'), { workerData: folders });
this.worker.addListener('message', (event) => {
const { methodName, result } = event;
if (methodName === 'onChanged') {
Expand Down

0 comments on commit 4095967

Please sign in to comment.