X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffixed.js;fp=lib%2Ffixed.js;h=645528283d80807cbc5374b5184c64b0f4c83c9e;hb=57df5469cb6f9ffd7c3501f026f2659b3cf88f06;hp=833ae7b6f1f048c8ff0a92e7eb42a1bdacd36b78;hpb=0003fe4e37d4d38c22d29d85d664baf762d4284e;p=poolifier.git diff --git a/lib/fixed.js b/lib/fixed.js index 833ae7b6..64552828 100644 --- a/lib/fixed.js +++ b/lib/fixed.js @@ -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