X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FyourWorker.js;h=5bd1ad6569c212b560d3eb829352f8974417b4a3;hb=7254e41972596ec68a8790747b9fd4ef0def5afc;hp=701aa8cf4d59cf15cd7623b0b09f8cbb0cef8928;hpb=a3c8691eb5bd772a43746fd5860d54a786463039;p=poolifier.git diff --git a/examples/yourWorker.js b/examples/yourWorker.js index 701aa8cf..5bd1ad65 100644 --- a/examples/yourWorker.js +++ b/examples/yourWorker.js @@ -1,20 +1,18 @@ 'use strict' -const { ThreadWorker } = require('../lib/workers') +const { ThreadWorker } = require('poolifier') +const { isMainThread } = require('worker_threads') -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)