X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FmultiFunctionExample.js;h=829ba93d4c59e852f872a47c6d5dbaa9dc4c5597;hb=daf86646c7cdb484ec05165a49c12224da11a4c7;hp=93d4e78b3d0465b35b823fd18dc2cbc203c66e31;hpb=5c5a1fb79906f18560012263239e7bd611ee8d2b;p=poolifier.git diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 93d4e78b..829ba93d 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,16 +1,21 @@ -const { FixedThreadPool } = require('poolifier') -const pool = new FixedThreadPool(15, './multiFunctionWorker.js', { - errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') -}) +const { FixedThreadPool, availableParallelism } = require('poolifier') + +const pool = new FixedThreadPool( + availableParallelism(), + './multiFunctionWorker.js', + { + errorHandler: e => console.error(e), + onlineHandler: () => console.info('worker is online') + } +) pool - .execute({ functionName: 'fn0', input: 'hello' }) - .then(res => console.log(res)) + .execute({ text: 'hello' }, 'fn0') + .then(res => console.info(res)) .catch(err => console.error(err)) pool - .execute({ functionName: 'fn1', input: 'multiple functions' }) - .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)