| 1 | 'use strict' |
| 2 | const { FixedThreadPool, availableParallelism } = require('poolifier') |
| 3 | |
| 4 | const pool = new FixedThreadPool( |
| 5 | availableParallelism(), |
| 6 | './multiFunctionWorker.js', |
| 7 | { |
| 8 | errorHandler: e => console.error(e), |
| 9 | onlineHandler: () => console.info('worker is online') |
| 10 | } |
| 11 | ) |
| 12 | |
| 13 | pool |
| 14 | .execute({ text: 'hello' }, 'fn0') |
| 15 | .then(res => console.info(res)) |
| 16 | .catch(err => console.error(err)) |
| 17 | pool |
| 18 | .execute({ text: 'multiple functions' }, 'fn1') |
| 19 | .then(res => console.info(res)) |
| 20 | .catch(err => console.error(err)) |
| 21 | |
| 22 | setTimeout(pool.destroy(), 3000) |