Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
fix: add types for JobMessage and ConfigMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 5, 2021
1 parent 9f41379 commit 856ec7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ConfigSchema } from "./config"
import type { emit } from 'node:cluster';
import type * as Tslint from "tslint";
import type * as Ts from "typescript";
import type { JobMessage, ConfigMessage } from "./workerHelper"

process.title = 'linter-tslint worker';

Expand Down Expand Up @@ -258,7 +259,7 @@ export default async function TsLintWorker(initialConfig: ConfigSchema) {
config.useGlobalTslint = initialConfig.useGlobalTslint;
config.globalNodePath = initialConfig.globalNodePath;

process.on('message', async (message) => {
process.on('message', async (message: JobMessage | ConfigMessage) => {
if (message.messageType === 'config') {
config[message.message.key] = message.message.value;

Expand Down
28 changes: 23 additions & 5 deletions lib/workerHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Task } from 'atom';
import { Task, TextEditor } from 'atom';
import type { ConfigSchema } from "./config"
import cryptoRandomString from 'crypto-random-string';

Expand Down Expand Up @@ -26,16 +26,16 @@ export default class WorkerHelper {
}
}

changeConfig(key, value) {
changeConfig(key: string, value: any) {
if (this.workerInstance) {
this.workerInstance.send({
messageType: 'config',
message: { key, value },
});
} as ConfigMessage);
}
}

requestJob(jobType, textEditor) {
requestJob(jobType: string, textEditor: TextEditor) {
if (!this.workerInstance) {
throw new Error("Worker hasn't started");
}
Expand Down Expand Up @@ -66,10 +66,28 @@ export default class WorkerHelper {
content: textEditor.getText(),
filePath: textEditor.getPath(),
},
});
} as JobMessage);
} catch (e) {
reject(e);
}
});
}
}

export type ConfigMessage = {
messageType: 'config',
message: {
key: string,
value: any,
}
}

export type JobMessage = {
messageType: 'job',
message: {
emitKey: string,
jobType: string,
content: ReturnType<TextEditor["getText"]>,
filePath: ReturnType<TextEditor["getPath"]>,
}
}

0 comments on commit 856ec7c

Please sign in to comment.