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