Open mlsad3 opened 4 years ago
Hmm, it seems to happen whenever I do anything inside the job (like create a new instance):
const res1 = await job(() => {
const configValidationManager = new ConfigValidationManager();
let i = 0;
for (i = 0; i < 1000000; i++) {}
return i;
});
This gives: Error: ConfigValidation_manager_1 is not defined Using Node 12.16.1, microjob 0.7.0
Looking at the .js file that TypeScript generates, I see the following:
const immutable_1 = require("immutable");
const ConfigValidation_manager_1 = __importDefault(require("./ConfigValidation.manager"));
const microjob_1 = require("microjob");
const errors_1 = require("../controllers/errors");
So it looks like the 'import' commands I have in my file won't work as they are not in the same scope as the worker...and my worker calls dozens of functions which also use various libraries, so they would all have similar issues.
I moved all of the processing code to another file, with a couple exports:
File: My.worker.ts
export { processRawConfigWorker };
Then in Main.ts:
try {
// Start worker pool
await start();
// This function will be executed in another thread
const res = await job(
data => {
const { processRawConfigWorker } = require('My.worker');
return processRawConfigWorker(data.rawConfig);
},
{ data: { rawConfig: rawConfig } }
);
return res;
} catch (err) {
console.error(err);
}
But this creates the error: "Cannot find module 'My.worker'".
Does anyone have an example using TypeScript and calling a function in another file? I tried prefixing with __dirName, but that just added '.' to the name.
Hi,
This library looks really cool. Unfortunately I hit a snag when I try to use 'immutable'. For example:
In the above example, it fails immediately with "immutable_1 is not defined". Is this a known limitation due to the way Immutable was written (using factories)? Thanks!