Skip to content

Commit

Permalink
Added a timeout on pQueue instance
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Jan 17, 2023
1 parent dbd37d0 commit 0b78b97
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
4 changes: 1 addition & 3 deletions lib/src/ocr-manager.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/src/pdf-manager.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0b78b97

Please sign in to comment.