Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "microjob", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A tiny wrapper for Node.js worker_threads lib", | ||
@@ -5,0 +5,0 @@ "main": "src/job.js", |
@@ -30,13 +30,15 @@ const v8 = require('v8') | ||
const dataStr = JSON.stringify(config.data) | ||
const dataSerialized = v8.serialize(config.data) | ||
const dataStr = JSON.stringify(dataSerialized) | ||
const workerStr = ` | ||
async function __executor__() { | ||
const v8 = require('v8') | ||
${variables} | ||
return await (${handler.toString()})(JSON.parse('${dataStr}')) | ||
const dataParsed = JSON.parse('${dataStr}') | ||
const dataBuffer = Buffer.from(dataParsed.data) | ||
const dataDeserialized = v8.deserialize(dataBuffer) | ||
return await (${handler.toString()})(dataDeserialized) | ||
} | ||
` | ||
// serialization precheck, due to this issue: https://github.com/nodejs/node/issues/22736 | ||
v8.serialize(config.data) | ||
worker.once('message', message => { | ||
@@ -43,0 +45,0 @@ workerPool.free(worker) |
@@ -16,3 +16,3 @@ const { Worker } = require('worker_threads') | ||
for (let i = 0; i < maxWorkers; i++) { | ||
const worker = new Worker('./src/worker.js') | ||
const worker = new Worker(`${__dirname}/worker.js`) | ||
@@ -19,0 +19,0 @@ worker.once('online', () => { |
8552
152