From ac4813b7109a88476f6f6b66c332aab1265d752b Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 18 Mar 2021 17:34:56 -0400 Subject: [PATCH] Clear OCR Timeout --- commands/analyze/ocr.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/analyze/ocr.js b/commands/analyze/ocr.js index 3b872ade..05c51c75 100644 --- a/commands/analyze/ocr.js +++ b/commands/analyze/ocr.js @@ -33,7 +33,9 @@ module.exports = class OcrCommand extends Command { await worker.loadLanguage('eng'); await worker.initialize('eng'); let timedOut = false; - setTimeout(async () => { + let finished = false; + const timeout = setTimeout(async () => { + if (finished) return; timedOut = true; await worker.terminate(); await reactIfAble(msg, msg.author, FAILURE_EMOJI_ID, '❌'); @@ -41,6 +43,7 @@ module.exports = class OcrCommand extends Command { }, 30000); const { data: { text } } = await worker.recognize(image); if (timedOut) return null; + clearTimeout(timeout); await worker.terminate(); await reactIfAble(msg, this.client.user, SUCCESS_EMOJI_ID, '✅'); if (!text) return msg.reply('There is no text in this image.');