Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | const { ThreadWorker } = require('poolifier') | |
3 | const { isMainThread } = require('worker_threads') | |
4 | ||
5 | const debug = false | |
6 | ||
7 | function yourFunction () { | |
8 | for (let i = 0; i <= 1000; i++) { | |
9 | const o = { | |
10 | a: i | |
11 | } | |
12 | JSON.stringify(o) | |
13 | } | |
14 | debug === true && console.log('This is the main thread ' + isMainThread) | |
15 | return { ok: 1 } | |
16 | } | |
17 | ||
18 | module.exports = new ThreadWorker(yourFunction) |