X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2FdynamicExample.js;h=4003c53462878652804fb8a051feeb792553c051;hb=0289646090c766a451aab11e7ab67a65f07221e4;hp=22379f204bf5a8a504920e06fea498e76f39f728;hpb=87a12b1289a70e4b26f2ea40ba3cbfc2ad4d97ea;p=poolifier.git diff --git a/examples/dynamicExample.js b/examples/dynamicExample.js index 22379f20..4003c534 100644 --- a/examples/dynamicExample.js +++ b/examples/dynamicExample.js @@ -1,4 +1,4 @@ -const DynamicThreadPool = require('../lib/dynamic') +const { DynamicThreadPool } = require('poolifier') let resolved = 0 let maxReached = 0 const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { @@ -10,11 +10,15 @@ pool.emitter.on('FullPool', () => maxReached++) const start = Date.now() const iterations = 1000 for (let i = 0; i <= iterations; i++) { - pool.execute({}).then(res => { - resolved++ - if (resolved === iterations) { - console.log('Time take is ' + (Date.now() - start)) - console.log('The pool was full for ' + maxReached + ' times') - } - }) + pool + .execute({}) + .then(res => { + resolved++ + if (resolved === iterations) { + console.log('Time take is ' + (Date.now() - start)) + return console.log('The pool was full for ' + maxReached + ' times') + } + return null + }) + .catch(err => console.error(err)) }