From 0b78b976530122e51335dff88cdb24fc29298a41 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Tue, 17 Jan 2023 20:00:06 +0100 Subject: [PATCH] Added a timeout on pQueue instance --- lib/src/globals.ts | 7 ++++--- lib/src/ocr-manager.ts | 4 +--- lib/src/pdf-manager.ts | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/src/globals.ts b/lib/src/globals.ts index 89f2c33..bc380fa 100644 --- a/lib/src/globals.ts +++ b/lib/src/globals.ts @@ -11,8 +11,9 @@ if (backgroundProcesses == cpuCount) { } console.info( - `Text Extractor - Number of available workers: ${backgroundProcesses}` + `Text Extractor - Number of available workers: ${backgroundProcesses}`, ) -// export const processQueue = pLimit(backgroundProcesses) -export const processQueue = new PQueue({ concurrency: backgroundProcesses }) +export const workerTimeout = 120_000 + +export const processQueue = new PQueue({ concurrency: backgroundProcesses, timeout: workerTimeout + 100 }) diff --git a/lib/src/ocr-manager.ts b/lib/src/ocr-manager.ts index caf9905..78cbf7a 100644 --- a/lib/src/ocr-manager.ts +++ b/lib/src/ocr-manager.ts @@ -1,11 +1,9 @@ import { Platform, TFile } from 'obsidian' import Tesseract, { createWorker } from 'tesseract.js' import { getCachePath, readCache, writeCache } from './cache' -import { processQueue } from './globals' +import { processQueue, workerTimeout } from './globals' import type { OcrOptions } from './types' -const workerTimeout = 120_000 - class OCRWorker { static #pool: OCRWorker[] = [] #running = false diff --git a/lib/src/pdf-manager.ts b/lib/src/pdf-manager.ts index 52e902e..bf91dd6 100644 --- a/lib/src/pdf-manager.ts +++ b/lib/src/pdf-manager.ts @@ -1,10 +1,8 @@ import { Platform, TFile } from 'obsidian' import WebWorker from 'web-worker:./pdf-worker.ts' -import { processQueue } from './globals' +import { processQueue, workerTimeout } from './globals' import { getCachePath, readCache, writeCache } from './cache' -const workerTimeout = 120_000 - class PDFWorker { static #pool: PDFWorker[] = [] #running = false