Benchmarking
[poolifier.git] / lib / fixed.js
index 833ae7b6f1f048c8ff0a92e7eb42a1bdacd36b78..645528283d80807cbc5374b5184c64b0f4c83c9e 100644 (file)
@@ -2,7 +2,6 @@
 const {
   Worker, isMainThread, MessageChannel, SHARE_ENV
 } = require('worker_threads')
-const { generateID } = require('./util')
 
 function empty () {}
 /**
@@ -26,6 +25,7 @@ class FixedThreadPool {
     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++) {
@@ -48,7 +48,7 @@ class FixedThreadPool {
     // 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