refactor: refine code examples
[poolifier.git] / README.md
index affe8bc91ce03bc3ad3f6c71448203026ee40eaa..c0d1e26a7fbf2e06aefa3d98686fb399e26e331c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -116,8 +116,8 @@ const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {
   onlineHandler: () => console.info('worker is online')
 })
 
-pool.emitter.on(PoolEvents.ready, () => console.info('Pool is ready'))
-pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy'))
+pool.emitter?.on(PoolEvents.ready, () => console.info('Pool is ready'))
+pool.emitter?.on(PoolEvents.busy, () => console.info('Pool is busy'))
 
 // or a dynamic worker_threads pool
 const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), './yourWorker.js', {
@@ -125,9 +125,9 @@ const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), avail
   onlineHandler: () => console.info('worker is online')
 })
 
-pool.emitter.on(PoolEvents.full, () => console.info('Pool is full'))
-pool.emitter.on(PoolEvents.ready, () => console.info('Pool is ready'))
-pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy'))
+pool.emitter?.on(PoolEvents.full, () => console.info('Pool is full'))
+pool.emitter?.on(PoolEvents.ready, () => console.info('Pool is ready'))
+pool.emitter?.on(PoolEvents.busy, () => console.info('Pool is busy'))
 
 // the execute method signature is the same for both implementations,
 // so you can easily switch from one to another