build(deps-dev): bump @types/node
[poolifier.git] / examples / javascript / multiFunctionExample.js
CommitLineData
670ede1c 1'use strict'
6961ca9a
JB
2const { FixedThreadPool, availableParallelism } = require('poolifier')
3
4const pool = new FixedThreadPool(
5 availableParallelism(),
6 './multiFunctionWorker.js',
7 {
8ebe6c30 8 errorHandler: (e) => console.error(e),
6961ca9a
JB
9 onlineHandler: () => console.info('worker is online')
10 }
11)
106744f7 12
583a27ce 13pool
a86b6df1 14 .execute({ text: 'hello' }, 'fn0')
8ebe6c30
JB
15 .then((res) => console.info(res))
16 .catch((err) => console.error(err))
cf9aa6c3 17pool
a86b6df1 18 .execute({ text: 'multiple functions' }, 'fn1')
8ebe6c30
JB
19 .then((res) => console.info(res))
20 .catch((err) => console.error(err))
106744f7 21
979e2251 22setTimeout(pool.destroy(), 3000)