refactor: cleanup cluster ESM issue workaround
[poolifier.git] / examples / multiFunctionExample.js
... / ...
CommitLineData
1'use strict'
2const { FixedThreadPool, availableParallelism } = require('poolifier')
3
4const 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
13pool
14 .execute({ text: 'hello' }, 'fn0')
15 .then(res => console.info(res))
16 .catch(err => console.error(err))
17pool
18 .execute({ text: 'multiple functions' }, 'fn1')
19 .then(res => console.info(res))
20 .catch(err => console.error(err))
21
22setTimeout(pool.destroy(), 3000)