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

Commit

Permalink
fix: null-check for workerInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 5, 2021
1 parent b1bcd04 commit 08310e7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/workerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cryptoRandomString from 'crypto-random-string';
import type * as Tslint from "tslint";

export class WorkerHelper {
workerInstance: Task
workerInstance: Task | null
constructor() {
this.workerInstance = null;
}
Expand Down Expand Up @@ -37,13 +37,16 @@ export class WorkerHelper {
}

async requestJob(jobType: string, textEditor: TextEditor): Promise<Tslint.LintResult[]> {
if (!this.workerInstance) {
if (this.workerInstance === null) {
throw new Error("Worker hasn't started");
}

const emitKey = await cryptoRandomString.async({ length: 10 });

return new Promise((resolve, reject) => {
if (this.workerInstance === null) {
throw new Error("Worker hasn't started");
}
const errSub = this.workerInstance.on('task:error', (...err) => {
// Re-throw errors from the task
const error = new Error(err[0]);
Expand Down

0 comments on commit 08310e7

Please sign in to comment.