X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FmultiFunctionExample.js;h=829ba93d4c59e852f872a47c6d5dbaa9dc4c5597;hb=13a332e67a8a208b09c673d8a4a132df657ff4e6;hp=76b6bbfbff95a347c677e81c6587d5df8c1e2da6;hpb=cf9aa6c3340ad00792aa3c5e1a9d047cd0140fc2;p=poolifier.git diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 76b6bbfb..829ba93d 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,12 +1,21 @@ -const FixedThreadPool = require('../lib/fixed') -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)