perf: workaround ESM issue with cluster
[poolifier.git] / benchmarks / internal / cluster-worker.js
diff --git a/benchmarks/internal/cluster-worker.js b/benchmarks/internal/cluster-worker.js
new file mode 100644 (file)
index 0000000..18bd648
--- /dev/null
@@ -0,0 +1,15 @@
+const { isPrimary } = require('node:cluster')
+const { ClusterWorker } = require('../../lib')
+const { executeTaskFunction } = require('../benchmarks-utils.js')
+const { TaskFunctions } = require('../benchmarks-types.js')
+
+const taskFunction = data => {
+  data = data || {}
+  data.function = data.function || TaskFunctions.jsonIntegerSerialization
+  data.debug = data.debug || false
+  const res = executeTaskFunction(data)
+  data.debug === true && console.debug(`This is the main thread ${isPrimary}`)
+  return res
+}
+
+module.exports = new ClusterWorker(taskFunction)