UNPKG

worker-union

Version:

🤼‍♂️ Package that makes it easy and convenient to use native worker_threads module

21 lines (15 loc) 437 B
const path = require('path'); const WorkerPool = require('../WorkerPool'); const workerPath = path.join(__dirname, 'worker.js'); /* eslint-disable no-param-reassign */ module.exports = (func, options = {}) => { delete options.initialData; delete options.path; const pool = new WorkerPool({ initialData: func.toString(), path: workerPath, ...options, }); pool.start(); return (...args) => pool.send(args); };