From 53795b86368cc6c3ec0648706fa385bdb6ca316d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 27 Jun 2023 22:25:56 +0200 Subject: [PATCH] docs: refine README.md MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 16 +++++++++++----- examples/dynamicExample.js | 8 ++++---- examples/fixedExample.js | 6 +++--- examples/multiFunctionExample.js | 6 +++--- examples/multiFunctionWorker.js | 4 ++-- examples/typescript/pool.ts | 4 ++-- examples/yourWorker.js | 2 +- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1a4cf823..d16fe946 100644 --- a/README.md +++ b/README.md @@ -117,15 +117,21 @@ Instantiate your pool based on your needs : const { DynamicThreadPool, FixedThreadPool, PoolEvents } = require('poolifier') // a fixed worker-threads pool -const pool = new FixedThreadPool(15, './yourWorker.js', { errorHandler: e => console.error(e), onlineHandler: () => console.log('worker is online') }) +const pool = new FixedThreadPool(15, './yourWorker.js', { + errorHandler: e => console.error(e), + onlineHandler: () => console.info('worker is online') +}) -pool.emitter.on(PoolEvents.busy, () => console.log('Pool is busy')) +pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy')) // or a dynamic worker-threads pool -const pool = new DynamicThreadPool(10, 100, './yourWorker.js', { errorHandler: e => console.error(e), onlineHandler: () => console.log('worker is online') }) +const pool = new DynamicThreadPool(10, 100, './yourWorker.js', { + errorHandler: e => console.error(e), + onlineHandler: () => console.info('worker is online') +}) -pool.emitter.on(PoolEvents.full, () => console.log('Pool is full')) -pool.emitter.on(PoolEvents.busy, () => console.log('Pool is busy')) +pool.emitter.on(PoolEvents.full, () => console.info('Pool is full')) +pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy')) // the execute method signature is the same for both implementations, // so you can easy switch from one to another diff --git a/examples/dynamicExample.js b/examples/dynamicExample.js index 1b7391d7..59d992a6 100644 --- a/examples/dynamicExample.js +++ b/examples/dynamicExample.js @@ -4,7 +4,7 @@ let poolFull = 0 let poolBusy = 0 const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + onlineHandler: () => console.info('worker is online') }) pool.emitter.on(PoolEvents.full, () => poolFull++) pool.emitter.on(PoolEvents.busy, () => poolBusy++) @@ -17,9 +17,9 @@ for (let i = 1; i <= iterations; i++) { .then(() => { resolved++ if (resolved === iterations) { - console.log('Time taken is ' + (performance.now() - start)) - console.log('The pool was full for ' + poolFull + ' times') - return console.log('The pool was busy for ' + poolBusy + ' times') + console.info('Time taken is ' + (performance.now() - start)) + console.info('The pool was full for ' + poolFull + ' times') + return console.info('The pool was busy for ' + poolBusy + ' times') } return null }) diff --git a/examples/fixedExample.js b/examples/fixedExample.js index 3f103ca5..478c37eb 100644 --- a/examples/fixedExample.js +++ b/examples/fixedExample.js @@ -3,7 +3,7 @@ let resolved = 0 let poolBusy = 0 const pool = new FixedThreadPool(15, './yourWorker.js', { errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + onlineHandler: () => console.info('worker is online') }) pool.emitter.on(PoolEvents.busy, () => poolBusy++) @@ -15,8 +15,8 @@ for (let i = 1; i <= iterations; i++) { .then(() => { resolved++ if (resolved === iterations) { - console.log('Time taken is ' + (performance.now() - start)) - return console.log('The pool was busy for ' + poolBusy + ' times') + console.info('Time taken is ' + (performance.now() - start)) + return console.info('The pool was busy for ' + poolBusy + ' times') } return null }) diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 213736ea..055f143f 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -1,16 +1,16 @@ const { FixedThreadPool } = require('poolifier') const pool = new FixedThreadPool(15, './multiFunctionWorker.js', { errorHandler: e => console.error(e), - onlineHandler: () => console.log('worker is online') + onlineHandler: () => console.info('worker is online') }) pool .execute({ text: 'hello' }, 'fn0') - .then(res => console.log(res)) + .then(res => console.info(res)) .catch(err => console.error(err)) pool .execute({ text: 'multiple functions' }, 'fn1') - .then(res => console.log(res)) + .then(res => console.info(res)) .catch(err => console.error(err)) setTimeout(pool.destroy(), 3000) diff --git a/examples/multiFunctionWorker.js b/examples/multiFunctionWorker.js index 53217fa0..406afa69 100644 --- a/examples/multiFunctionWorker.js +++ b/examples/multiFunctionWorker.js @@ -2,12 +2,12 @@ const { ThreadWorker } = require('poolifier') function fn0 (data) { - console.log('Executing function 0') + console.info('Executing function 0') return { data: 'fn0 your input text was' + data.text } } function fn1 (data) { - console.log('Executing function 1') + console.info('Executing function 1') return { data: 'fn1 your input text was' + data.text } } diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index 7268ebdc..869e62a8 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -10,7 +10,7 @@ export const fixedPool = new FixedThreadPool>( console.error(e) }, onlineHandler: () => { - console.log('Worker is online') + console.info('Worker is online') } } ) @@ -24,7 +24,7 @@ export const dynamicPool = new DynamicThreadPool>( console.error(e) }, onlineHandler: () => { - console.log('Worker is online') + console.info('Worker is online') } } ) diff --git a/examples/yourWorker.js b/examples/yourWorker.js index 7de9485c..b2df8d19 100644 --- a/examples/yourWorker.js +++ b/examples/yourWorker.js @@ -11,7 +11,7 @@ function yourFunction () { } JSON.stringify(o) } - debug === true && console.log('This is the main thread ' + isMainThread) + debug === true && console.info('This is the main thread ' + isMainThread) return { ok: 1 } } -- 2.34.1