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
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++)
.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
})
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++)
.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
})
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)
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 }
}
console.error(e)
},
onlineHandler: () => {
- console.log('Worker is online')
+ console.info('Worker is online')
}
}
)
console.error(e)
},
onlineHandler: () => {
- console.log('Worker is online')
+ console.info('Worker is online')
}
}
)
}
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 }
}