From 08310e7df448ec7c6c681e972b47561be4443b99 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 5 Apr 2021 04:51:59 -0500 Subject: [PATCH] fix: null-check for workerInstance --- lib/workerHelper.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/workerHelper.ts b/lib/workerHelper.ts index e2285412..66a4664a 100644 --- a/lib/workerHelper.ts +++ b/lib/workerHelper.ts @@ -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; } @@ -37,13 +37,16 @@ export class WorkerHelper { } async requestJob(jobType: string, textEditor: TextEditor): Promise { - 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]);