build: bump volta node version
[poolifier.git] / examples / javascript / multiFunctionExample.cjs
1 'use strict'
2 const { FixedThreadPool, availableParallelism } = require('poolifier')
3
4 const pool = new FixedThreadPool(
5 availableParallelism(),
6 './multiFunctionWorker.cjs',
7 {
8 onlineHandler: () => console.info('worker is online'),
9 errorHandler: e => console.error(e)
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(async () => await pool.destroy(), 3000)