Added prettier standard to support prettier and use it in combination with standard
[poolifier.git] / lib / fixed.js
index 676947725bed0bb65fe72fe949be8652b08f39c5..f5ad269580a5d5475ff0a36a0a115f5ff30c6eb8 100644 (file)
@@ -1,6 +1,9 @@
 'use strict'
 const {
-  Worker, isMainThread, MessageChannel, SHARE_ENV
+  Worker,
+  isMainThread,
+  MessageChannel,
+  SHARE_ENV
 } = require('worker_threads')
 
 function empty () {}
@@ -13,14 +16,18 @@ const _void = {}
  */
 class FixedThreadPool {
   /**
-    *
-    * @param {Number} numThreads  Num of threads for this worker pool
-    * @param {string} a file path with implementation of @see ThreadWorker class, relative path is fine
-    * @param {Object} an object with possible options for example errorHandler, onlineHandler.
-  */
+   *
+   * @param {Number} numThreads  Num of threads for this worker pool
+   * @param {string} a file path with implementation of @see ThreadWorker class, relative path is fine
+   * @param {Object} an object with possible options for example errorHandler, onlineHandler.
+   */
   constructor (numThreads, filePath, opts) {
-    if (!isMainThread) throw new Error('Cannot start a thread pool from a worker thread !!!')
-    if (!filePath) throw new Error('Please specify a file with a worker implementation')
+    if (!isMainThread) {
+      throw new Error('Cannot start a thread pool from a worker thread !!!')
+    }
+    if (!filePath) {
+      throw new Error('Please specify a file with a worker implementation')
+    }
     this.numThreads = numThreads
     this.workers = []
     this.nextWorker = 0
@@ -57,7 +64,7 @@ class FixedThreadPool {
 
   _execute (worker, id) {
     return new Promise((resolve, reject) => {
-      const listener = (message) => {
+      const listener = message => {
         if (message._id === id) {
           worker.port2.removeListener('message', listener)
           this.tasks.set(worker, this.tasks.get(worker) - 1)
@@ -70,7 +77,7 @@ class FixedThreadPool {
   }
 
   _chooseWorker () {
-    if ((this.workers.length - 1) === this.nextWorker) {
+    if (this.workers.length - 1 === this.nextWorker) {
       this.nextWorker = 0
       return this.workers[this.nextWorker]
     } else {