/** * * Node worker implementation * * @fileoverview Node worker implementation * @author Kevin Kwok * @author Guillermo Webster * @author Jerome Wu */ const check = require('check-types'); const workerUtils = require('../common/workerUtils'); let TesseractCore = null; /* * register message handler */ process.on('message', (packet) => { workerUtils.dispatchHandlers(packet, obj => process.send(obj)); }); /* * getCore is a sync function to load and return * TesseractCore. */ workerUtils.setAdapter({ getCore: (corePath, res) => { if (check.null(TesseractCore)) { res.progress({ status: 'loading tesseract core', progress: 0 }); TesseractCore = require('tesseract.js-core'); res.progress({ status: 'loaded tesseract core', progress: 1 }); } return TesseractCore; }, });