Commit | Line | Data |
---|---|---|
670ede1c | 1 | 'use strict' |
97231086 | 2 | const { availableParallelism, FixedThreadPool } = require('poolifier') |
6961ca9a JB |
3 | |
4 | const pool = new FixedThreadPool( | |
5 | availableParallelism(), | |
d35e5717 | 6 | './multiFunctionWorker.cjs', |
6961ca9a | 7 | { |
3a502712 | 8 | errorHandler: e => console.error(e), |
97231086 | 9 | onlineHandler: () => console.info('worker is online'), |
6961ca9a JB |
10 | } |
11 | ) | |
106744f7 | 12 | |
583a27ce | 13 | pool |
a86b6df1 | 14 | .execute({ text: 'hello' }, 'fn0') |
041dc05b JB |
15 | .then(res => console.info(res)) |
16 | .catch(err => console.error(err)) | |
cf9aa6c3 | 17 | pool |
a86b6df1 | 18 | .execute({ text: 'multiple functions' }, 'fn1') |
041dc05b JB |
19 | .then(res => console.info(res)) |
20 | .catch(err => console.error(err)) | |
106744f7 | 21 | |
9dadc18f | 22 | setTimeout(async () => await pool.destroy(), 3000) |