From b87afe9d93c2f96fcb1cac717710c631c954c5fb Mon Sep 17 00:00:00 2001 From: Balearica Date: Sat, 17 Sep 2022 13:50:08 -0700 Subject: [PATCH] Reworked createWorker to be async and throw errors per #654 --- examples/node/benchmark.js | 4 +--- examples/node/download-pdf.js | 3 +-- examples/node/recognize.js | 7 +++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/node/benchmark.js b/examples/node/benchmark.js index 728d1d5..28d3fe7 100644 --- a/examples/node/benchmark.js +++ b/examples/node/benchmark.js @@ -2,10 +2,8 @@ const path = require('path'); const { createWorker } = require('../../'); -const worker = createWorker(); - (async () => { - await worker.load(); + const worker = await createWorker(); await worker.loadLanguage('eng'); await worker.initialize('eng'); const fileArr = ["../data/meditations.jpg", "../data/tyger.jpg", "../data/testocr.png"]; diff --git a/examples/node/download-pdf.js b/examples/node/download-pdf.js index f61e55c..2f7ed24 100755 --- a/examples/node/download-pdf.js +++ b/examples/node/download-pdf.js @@ -9,8 +9,7 @@ const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/c console.log(`Recognizing ${image}`); (async () => { - const worker = createWorker(); - await worker.load(); + const worker = await createWorker(); await worker.loadLanguage('eng'); await worker.initialize('eng'); const { data: { text } } = await worker.recognize(image); diff --git a/examples/node/recognize.js b/examples/node/recognize.js index c77955e..082ffa0 100755 --- a/examples/node/recognize.js +++ b/examples/node/recognize.js @@ -6,12 +6,11 @@ const [,, imagePath] = process.argv; const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png')); console.log(`Recognizing ${image}`); -const worker = createWorker({ - logger: m => console.log(m), -}); (async () => { - await worker.load(); + const worker = await createWorker({ + logger: m => console.log(m), + }); await worker.loadLanguage('eng'); await worker.initialize('eng'); const { data: { text } } = await worker.recognize(image);