I'm trying to use worker threads in my Meteor app to offload CPU intensive tasks. I'm using the @arrows/worker library instead of the worker_threads module directly. I tried some very simple test code (below), but got the following error.
events.js:288
throw er; // Unhandled 'error' event
^
ReferenceError: meteorInstall is not defined
at Object.<anonymous> (meteor://app/app/app.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at MessagePort.<anonymous> (internal/main/worker_thread.js:162:24)
at MessagePort.emit (events.js:311:20)
at MessagePort.onmessage (internal/worker/io.js:78:8)
Emitted 'error' event on Worker instance at:
at Worker.[kOnErrorMessage] (internal/worker.js:204:10)
at Worker.[kOnMessage] (internal/worker.js:214:37)
at MessagePort.<anonymous> (internal/worker.js:141:57)
at MessagePort.emit (events.js:311:20)
at MessagePort.EventEmitter.emit (domain.js:482:12)
at MessagePort.onmessage (internal/worker/io.js:78:8)
Test code:
import worker from '@arrows/worker';
const fn = function (data) {
console.log('fn');
return 'abc';
};
const asyncFn = worker(fn);
const runIt = async () => {
console.log('a');
try {
const out = await asyncFn('a');
console.log('b', out);
}
catch (err) { console.log(err); }
}
runIt();