X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FmultiFunctionExample.js;h=27a503256b776d163b29ad7a64a0a8d425ebf6c1;hb=0819631dfe372ae4930cb476a7a81fb2f2a86804;hp=76b6bbfbff95a347c677e81c6587d5df8c1e2da6;hpb=87a12b1289a70e4b26f2ea40ba3cbfc2ad4d97ea;p=poolifier.git diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 76b6bbfb..27a50325 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,12 +1,22 @@ -const FixedThreadPool = require('../lib/fixed') -const pool = new FixedThreadPool(15, './multifunctionWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') -}) +'use strict' +const { FixedThreadPool, availableParallelism } = require('poolifier') -pool.execute({ fname: 'fn0', input: 'hello' }).then(res => console.log(res)) +const pool = new FixedThreadPool( + availableParallelism(), + './multiFunctionWorker.js', + { + errorHandler: e => console.error(e), + onlineHandler: () => console.info('worker is online') + } +) + +pool + .execute({ text: 'hello' }, 'fn0') + .then(res => console.info(res)) + .catch(err => console.error(err)) pool - .execute({ fname: 'fn1', input: 'multifunction' }) - .then(res => console.log(res)) + .execute({ text: 'multiple functions' }, 'fn1') + .then(res => console.info(res)) + .catch(err => console.error(err)) -setTimeout(pool.destroy.bind(pool), 3000) +setTimeout(pool.destroy(), 3000)