const {
Worker, isMainThread, MessageChannel, SHARE_ENV
} = require('worker_threads')
-const { generateID } = require('./util')
function empty () {}
/**
this.nextWorker = 0
this.opts = opts || { maxTasks: 1000 }
this.filePath = filePath
+ this._id = 0
// threadId as key and an integer value
this.tasks = new Map()
for (let i = 1; i <= numThreads; i++) {
// configure worker to handle message with the specified task
const worker = this._chooseWorker()
this.tasks.set(worker, this.tasks.get(worker) + 1)
- const id = generateID()
+ const id = ++this._id
const res = this._execute(worker, id)
worker.postMessage({ data: data, _id: id })
return res