X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FyourWorker.js;h=7de9485ceb1a228075011e615fb802d7660185b4;hb=dab8c377b70fc962ec217f2aeb719842f9f94cd6;hp=5036d5746be21fe1b48310b7909f0f6f0fb057b3;hpb=c68d4281d92ef0da01fc89fb00a93d3a17ba392e;p=poolifier.git diff --git a/examples/yourWorker.js b/examples/yourWorker.js index 5036d574..7de9485c 100644 --- a/examples/yourWorker.js +++ b/examples/yourWorker.js @@ -1,19 +1,18 @@ 'use strict' -const { ThreadWorker } = require('../lib/workers') +const { isMainThread } = require('worker_threads') +const { ThreadWorker } = require('poolifier') -class MyWorker extends ThreadWorker { - constructor () { - super((data) => { - for (let i = 0; i <= 10000; i++) { - const o = { - a: i - } - JSON.stringify(o) - } - // console.log('This is the main thread ' + isMainThread) - return { ok: 1 } - }) +const debug = false + +function yourFunction () { + for (let i = 0; i <= 1000; i++) { + const o = { + a: i + } + JSON.stringify(o) } + debug === true && console.log('This is the main thread ' + isMainThread) + return { ok: 1 } } -module.exports = new MyWorker() +module.exports = new ThreadWorker(yourFunction)