X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FmultiFunctionExample.js;h=829ba93d4c59e852f872a47c6d5dbaa9dc4c5597;hb=0fc6cbb45e0571c5da4d2b523b7e55d9315d0aa5;hp=d1314aa94149fe7324fda3df0b91e240f9865532;hpb=60fbd6d6188b0902d157fd0cde04d6af3a391e32;p=poolifier.git diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index d1314aa9..829ba93d 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,12 +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') -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)