multiprocessor
Version:
Multiprocessing pool implementation for NodeJS and TypeScript
11 lines (10 loc) • 367 B
JavaScript
process.on('message', async (message) => {
const { taskFunctionString, inputData, taskIndex } = message;
const taskFunction = eval(`(${taskFunctionString})`);
try {
const result = await taskFunction(inputData);
process.send({ result, inputData, taskIndex });
} catch (error) {
process.send({ error: error.message, inputData, taskIndex });
}
});