Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
init?
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Jan 16, 2024
1 parent 525b89a commit 0af95e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/data/schemata/workerThreadMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import * as S from '@effect/schema/Schema';
import { consoleKindSchema } from './consoleKind';

const workerThreadMessageSchema = S.union(
S.struct({
kind: S.literal('commands'),
commands: S.unknown,
}),
S.struct({
kind: S.literal('error'),
message: S.string,
Expand Down
27 changes: 26 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import { GlobalStateTokenStorage, UserService } from './components/userService';
import { HomeDirectoryService } from './data/readHomeDirectoryCases';
import { isLeft } from 'fp-ts/lib/Either';
import { createClearStateCommand } from './commands/clearStateCommand';
import { isMainThread } from 'node:worker_threads';
import { isMainThread, Worker } from 'node:worker_threads';
import { executeWorkerThread } from './worker';
import { decodeWorkerThreadMessage } from './data/schemata/workerThreadMessage';

export const enum SEARCH_PARAMS_KEYS {
ENGINE = 'engine',
Expand All @@ -62,10 +63,34 @@ export const enum SEARCH_PARAMS_KEYS {
ACCESS_TOKEN = 'accessToken',
}

const WORKER_THREADS_COUNT = 10;

const messageBus = new MessageBus();

export async function activate(context: vscode.ExtensionContext) {
if (isMainThread) {
for (let i = 0; i < WORKER_THREADS_COUNT; ++i) {
const worker = new Worker(__filename);

worker.on('message', (m: unknown) => {
const workerThreadMessage = decodeWorkerThreadMessage(m);

if (workerThreadMessage.kind === 'console') {
console[workerThreadMessage.consoleKind](
workerThreadMessage.message,
);
return;
}

if (workerThreadMessage.kind === 'error') {
console.error(
workerThreadMessage.message,
workerThreadMessage.path,
);
}
});
}

execute(context).catch((error) => {
if (error instanceof Error) {
console.error(JSON.stringify({ message: error.message }));
Expand Down

0 comments on commit 0af95e2

Please sign in to comment.