refactor: renable standard JS linter rules
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 30 Dec 2023 09:40:58 +0000 (10:40 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 30 Dec 2023 09:40:58 +0000 (10:40 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
36 files changed:
.eslintrc.cjs
.lintstagedrc.js
.prettierrc.json
examples/typescript/http-client-pool/src/worker.ts
examples/typescript/http-server-pool/express-cluster/src/worker.ts
examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts
examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts
examples/typescript/http-server-pool/express-worker_threads/src/worker.ts
examples/typescript/http-server-pool/fastify-cluster/src/worker.ts
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts
examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts
examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts
examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts
examples/typescript/smtp-client-pool/src/worker.ts
examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts
examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts
examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts
examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts
package.json
pnpm-lock.yaml
src/deque.ts
src/pools/abstract-pool.ts
src/pools/cluster/dynamic.ts
src/pools/cluster/fixed.ts
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
src/pools/selection-strategies/fair-share-worker-choice-strategy.ts
src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/worker-choice-strategy-context.ts
src/pools/thread/dynamic.ts
src/pools/thread/fixed.ts
src/pools/worker-node.ts
src/worker/abstract-worker.ts
src/worker/cluster-worker.ts
src/worker/thread-worker.ts

index ccf04244362008396ba0ce730697bae073b49dfe..522fdce51d59bac6a4553e40a644a258d3341468 100644 (file)
@@ -121,7 +121,7 @@ module.exports = defineConfig({
         'standard-with-typescript'
       ],
       rules: {
-        '@typescript-eslint/non-nullable-type-assertion-style': 'off',
+        'operator-linebreak': 'off',
         'tsdoc/syntax': 'warn'
       }
     },
@@ -151,7 +151,8 @@ module.exports = defineConfig({
         '@typescript-eslint/no-unnecessary-type-assertion': 'off',
         '@typescript-eslint/no-redundant-type-constituents': 'off',
         '@typescript-eslint/strict-boolean-expressions': 'off',
-        '@typescript-eslint/return-await': 'off'
+        // '@typescript-eslint/return-await': 'off',
+        '@typescript-eslint/no-non-null-assertion': 'off'
       }
     },
     {
index 1886925b219e90889d85b37fb58572a850e12398..507f281dd6e4dd4ca0a744a53c4a4c918eb06262 100644 (file)
@@ -1,7 +1,6 @@
 export default {
   '**/*.{ts,tsx,js,jsx,cjs,mjs}': [
     'biome format --write',
-    'ts-standard --fix',
     'eslint --cache --fix'
   ],
   '**/!(package.json|tsconfig.json)*.json': ['biome format --write'],
index 80901f792fad9172596b1a8f7c9db1fd3ddb03d5..890136a148d82e4dc4e2e6b15101cf4862ba82ea 100644 (file)
@@ -2,5 +2,5 @@
   "$schema": "https://json.schemastore.org/prettierrc",
   "semi": false,
   "singleQuote": true,
-  "trailingComma": "none"
+  "trailingComma": "es5"
 }
index 63f77fd753ae02f7e5ac4d29b74a2065487347f5..1e89761f9439cb019e271de8620f1d52b0f1e67d 100644 (file)
@@ -11,7 +11,7 @@ class HttpClientWorker extends ThreadWorker<WorkerData, WorkerResponse> {
     super({
       node_fetch: async (workerData?: WorkerData) => {
         const response = await nodeFetch(
-          (workerData as WorkerData).input as URL | NodeFetchRequestInfo,
+          workerData!.input as URL | NodeFetchRequestInfo,
           workerData?.init as NodeFetchRequestInit
         )
         // The response is not structured-cloneable, so we return the response text body instead.
@@ -21,7 +21,7 @@ class HttpClientWorker extends ThreadWorker<WorkerData, WorkerResponse> {
       },
       fetch: async (workerData?: WorkerData) => {
         const response = await fetch(
-          (workerData as WorkerData).input as URL | RequestInfo,
+          workerData!.input as URL | RequestInfo,
           workerData?.init as RequestInit
         )
         // The response is not structured-cloneable, so we return the response text body instead.
@@ -32,7 +32,7 @@ class HttpClientWorker extends ThreadWorker<WorkerData, WorkerResponse> {
       axios: async (workerData?: WorkerData) => {
         const response = await axios({
           method: 'get',
-          url: (workerData as WorkerData).input as string,
+          url: workerData!.input as string,
           ...workerData?.axiosRequestConfig
         })
         return {
index 940503dfad3f241cceaefa3779060bd5f4afa1d8..7b7087301c29fccbf85dcb74c3fda3a0b0e7e49d 100644 (file)
@@ -17,7 +17,7 @@ class ExpressWorker extends ClusterWorker<WorkerData, WorkerResponse> {
   private static readonly startExpress = (
     workerData?: WorkerData
   ): WorkerResponse => {
-    const { port } = workerData as WorkerData
+    const { port } = workerData!
 
     const application: Express = express()
 
index c7ca23adee4a4c2c48ec5a06f9792f93d45438fe..ac2e34d43bfc9ab2f97f51c4a874f2dee782495c 100644 (file)
@@ -32,7 +32,7 @@ ClusterWorkerResponse
     workerData?: ClusterWorkerData
   ): ClusterWorkerResponse => {
     const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
-      workerData as ClusterWorkerData
+      workerData!
 
     ExpressWorker.requestHandlerPool = new DynamicThreadPool<
     ThreadWorkerData<DataPayload>,
index 8c247819488b5548f3e4fe1adbbaf106286cd3f4..ac4fb97aa0ee2e2a1e76e1d6db1521ddbde7f257 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           data: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.data?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.data.number!)
           }
         } as unknown as Response
       }
index 3f573647b34cef414a6b62baeb3227aefac29971..223ee36859fe2b0b2d1fd71704627e9928dfeb7f 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           body: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.body?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.body.number!)
           }
         } as unknown as Response
       }
index 2f6c8f6dec1fcf405c8ce5bdb78a51c84c7c1915..1551cb282ede3679ade624acb473a8ac2ab568c3 100644 (file)
@@ -16,7 +16,7 @@ class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
   private static readonly startFastify = async (
     workerData?: WorkerData
   ): Promise<WorkerResponse> => {
-    const { port } = workerData as WorkerData
+    const { port } = workerData!
 
     FastifyWorker.fastify = Fastify({
       logger: true
index 2bdf2040bbbb3354ea1d703318ca3832ba109904..3c5e31e34dc85c9583b29ba427d8cb66704cb686 100644 (file)
@@ -22,8 +22,8 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
   }
   const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options
   const pool = new DynamicThreadPool<ThreadWorkerData, ThreadWorkerResponse>(
-    minWorkers as number,
-    maxWorkers as number,
+    minWorkers!,
+    maxWorkers!,
     workerFile,
     poolOptions
   )
index 388730dcec9bda04a13315f4f0b5fb1814981266..28bf2a01f1cb0d15aff9b86d3bbbeed98c9bd808 100644 (file)
@@ -13,7 +13,7 @@ ClusterWorkerResponse
   private static readonly startFastify = async (
     workerData?: ClusterWorkerData
   ): Promise<ClusterWorkerResponse> => {
-    const { port, ...fastifyPoolifierOptions } = workerData as ClusterWorkerData
+    const { port, ...fastifyPoolifierOptions } = workerData!
 
     FastifyWorker.fastify = Fastify({
       logger: true
index 8c247819488b5548f3e4fe1adbbaf106286cd3f4..ac4fb97aa0ee2e2a1e76e1d6db1521ddbde7f257 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           data: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.data?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.data.number!)
           }
         } as unknown as Response
       }
index aa9a6d1459813c6a4cf66f0d2ce9795db5b63288..cd1909b7f3d7eab8f83f781971e452b7108e129d 100644 (file)
@@ -22,8 +22,8 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
   }
   const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options
   const pool = new DynamicThreadPool<WorkerData, WorkerResponse>(
-    minWorkers as number,
-    maxWorkers as number,
+    minWorkers!,
+    maxWorkers!,
     workerFile,
     poolOptions
   )
index 3f573647b34cef414a6b62baeb3227aefac29971..223ee36859fe2b0b2d1fd71704627e9928dfeb7f 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           body: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.body?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.body.number!)
           }
         } as unknown as Response
       }
index 448575d12cbe03a43c0c14de39d5d97c07b39ce7..01e49b0948a962ed93d29b110b3e0a3fe18b9c3a 100644 (file)
@@ -1,6 +1,5 @@
 import { ThreadWorker } from 'poolifier'
 import { createTransport } from 'nodemailer'
-import type Mail from 'nodemailer/lib/mailer/index.js'
 import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
 import type { WorkerData } from './types.js'
 
@@ -12,7 +11,7 @@ SMTPTransport.SentMessageInfo
     super({
       nodemailer: async (workerData?: WorkerData) => {
         return await createTransport(workerData?.smtpTransport).sendMail(
-          workerData?.mail as Mail.Options
+          workerData!.mail
         )
       }
     })
index 0e8dc20a95fd8d2f3f161381d07f90a36e60b933..18ece026c891efb3106499667027a1a2aba0b73a 100644 (file)
@@ -21,7 +21,7 @@ class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
   private static readonly startWebSocketServer = (
     workerData?: WorkerData
   ): WorkerResponse => {
-    const { port } = workerData as WorkerData
+    const { port } = workerData!
 
     WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {
       console.info(
@@ -50,7 +50,7 @@ class WebSocketServerWorker extends ClusterWorker<WorkerData, WorkerResponse> {
               JSON.stringify({
                 type: MessageType.factorial,
                 data: {
-                  number: WebSocketServerWorker.factorial(data.number as number)
+                  number: WebSocketServerWorker.factorial(data.number!)
                 }
               })
             )
index 8c247819488b5548f3e4fe1adbbaf106286cd3f4..ac4fb97aa0ee2e2a1e76e1d6db1521ddbde7f257 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           data: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.data?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.data.number!)
           }
         } as unknown as Response
       }
index 46745d9657cc9f700fc3f9ad79789b8323bf0715..4e6529e0975486de51c1f5d814dccdb61dff1687 100644 (file)
@@ -32,7 +32,7 @@ ClusterWorkerResponse
     workerData?: ClusterWorkerData
   ): ClusterWorkerResponse => {
     const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
-      workerData as ClusterWorkerData
+      workerData!
 
     WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
     ThreadWorkerData<DataPayload>,
index 6f9f0914d3fea36b438141217f56c177f8e7c4c2..a3b106c64d341d55d3a94d327c056da227f6bfdf 100644 (file)
@@ -24,9 +24,7 @@ class RequestHandlerWorker<
       factorial: (workerData?: Data) => {
         return {
           data: {
-            number: RequestHandlerWorker.factorial(
-              workerData?.data?.number as number
-            )
+            number: RequestHandlerWorker.factorial(workerData!.data.number!)
           }
         } as unknown as Response
       }
index e725f6f1d33d38b6c5ea11e0665c5966c274c5cc..d057f36f029e7cdc0ff1ec9fb963219772e8c29c 100644 (file)
     "eslint-import-resolver-typescript": "^3.6.1",
     "eslint-plugin-import": "^2.29.1",
     "eslint-plugin-jsdoc": "^46.9.1",
-    "eslint-plugin-n": "^16.5.0",
+    "eslint-plugin-n": "^16.6.0",
     "eslint-plugin-promise": "^6.1.1",
     "eslint-plugin-spellcheck": "^0.0.20",
     "eslint-plugin-tsdoc": "^0.2.17",
index b15b576fb8c8ad576d4d1ad5f63c0cbe10a9e0df..d2f1f5257e10ad82c4bf9423d210959678145102 100644 (file)
@@ -52,10 +52,10 @@ devDependencies:
     version: 8.56.0
   eslint-config-standard:
     specifier: ^17.1.0
-    version: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
+    version: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
   eslint-config-standard-with-typescript:
     specifier: ^43.0.0
-    version: 43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3)
+    version: 43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3)
   eslint-define-config:
     specifier: ^2.1.0
     version: 2.1.0
@@ -69,8 +69,8 @@ devDependencies:
     specifier: ^46.9.1
     version: 46.9.1(eslint@8.56.0)
   eslint-plugin-n:
-    specifier: ^16.5.0
-    version: 16.5.0(eslint@8.56.0)
+    specifier: ^16.6.0
+    version: 16.6.0(eslint@8.56.0)
   eslint-plugin-promise:
     specifier: ^6.1.1
     version: 6.1.1(eslint@8.56.0)
@@ -1298,16 +1298,16 @@ packages:
       through: 2.3.8
     dev: true
 
-  /acorn-jsx@5.3.2(acorn@8.11.2):
+  /acorn-jsx@5.3.2(acorn@8.11.3):
     resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
     peerDependencies:
       acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
     dependencies:
-      acorn: 8.11.2
+      acorn: 8.11.3
     dev: true
 
-  /acorn@8.11.2:
-    resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
+  /acorn@8.11.3:
+    resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==}
     engines: {node: '>=0.4.0'}
     hasBin: true
     dev: true
@@ -2458,7 +2458,7 @@ packages:
       - supports-color
     dev: true
 
-  /eslint-config-standard-with-typescript@43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3):
+  /eslint-config-standard-with-typescript@43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3):
     resolution: {integrity: sha512-AT0qK01M5bmsWiE3UZvaQO5da1y1n6uQckAKqGNe6zPW5IOzgMLXZxw77nnFm+C11nxAZXsCPrbsgJhSrGfX6Q==}
     peerDependencies:
       '@typescript-eslint/eslint-plugin': ^6.4.0
@@ -2471,9 +2471,9 @@ packages:
       '@typescript-eslint/eslint-plugin': 6.16.0(@typescript-eslint/parser@6.16.0)(eslint@8.56.0)(typescript@5.3.3)
       '@typescript-eslint/parser': 6.16.0(eslint@8.56.0)(typescript@5.3.3)
       eslint: 8.56.0
-      eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
+      eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
       eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0)
-      eslint-plugin-n: 16.5.0(eslint@8.56.0)
+      eslint-plugin-n: 16.6.0(eslint@8.56.0)
       eslint-plugin-promise: 6.1.1(eslint@8.56.0)
       typescript: 5.3.3
     transitivePeerDependencies:
@@ -2494,7 +2494,7 @@ packages:
       eslint-plugin-promise: 6.1.1(eslint@8.56.0)
     dev: true
 
-  /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0):
+  /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0):
     resolution: {integrity: sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==}
     engines: {node: '>=12.0.0'}
     peerDependencies:
@@ -2505,7 +2505,7 @@ packages:
     dependencies:
       eslint: 8.56.0
       eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0)
-      eslint-plugin-n: 16.5.0(eslint@8.56.0)
+      eslint-plugin-n: 16.6.0(eslint@8.56.0)
       eslint-plugin-promise: 6.1.1(eslint@8.56.0)
     dev: true
 
@@ -2737,8 +2737,8 @@ packages:
       semver: 7.5.4
     dev: true
 
-  /eslint-plugin-n@16.5.0(eslint@8.56.0):
-    resolution: {integrity: sha512-Hw02Bj1QrZIlKyj471Tb1jSReTl4ghIMHGuBGiMVmw+s0jOPbI4CBuYpGbZr+tdQ+VAvSK6FDSta3J4ib/SKHQ==}
+  /eslint-plugin-n@16.6.0(eslint@8.56.0):
+    resolution: {integrity: sha512-Ag3tYFF90lYU8JdHEl9qSSpeLYbVnO+Oj7sgPUarWUacv1mPL3d5h5yG4Bv3tLe71hrcxmgTi7oByYwKXaVatw==}
     engines: {node: '>=16.0.0'}
     peerDependencies:
       eslint: '>=7.0.0'
@@ -2748,6 +2748,7 @@ packages:
       eslint: 8.56.0
       eslint-plugin-es-x: 7.5.0(eslint@8.56.0)
       get-tsconfig: 4.7.2
+      globals: 13.24.0
       ignore: 5.3.0
       is-builtin-module: 3.2.1
       is-core-module: 2.13.1
@@ -2907,8 +2908,8 @@ packages:
     resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==}
     engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
     dependencies:
-      acorn: 8.11.2
-      acorn-jsx: 5.3.2(acorn@8.11.2)
+      acorn: 8.11.3
+      acorn-jsx: 5.3.2(acorn@8.11.3)
       eslint-visitor-keys: 3.4.3
     dev: true
 
@@ -6052,7 +6053,7 @@ packages:
     hasBin: true
     dependencies:
       '@jridgewell/source-map': 0.3.5
-      acorn: 8.11.2
+      acorn: 8.11.3
       commander: 2.20.3
       source-map-support: 0.5.21
     dev: true
index 723f1a4950688bcea0244e83a8f764b02cdf5a38..00f60e6f7256c5204969ac827d4533cfaf177994 100644 (file)
@@ -79,7 +79,8 @@ export class Deque<T> {
       return
     }
     const tail = this.tail
-    this.tail = (this.tail as Node<T>).prev
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    this.tail = this.tail!.prev
     if (this.tail == null) {
       delete this.head
     } else {
@@ -155,7 +156,8 @@ export class Deque<T> {
           value: node.data,
           done: false
         }
-        node = node.next as Node<T>
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        node = node.next!
         return ret
       }
     }
@@ -183,7 +185,8 @@ export class Deque<T> {
               value: node.data,
               done: false
             }
-            node = node.prev as Node<T>
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            node = node.prev!
             return ret
           }
         }
index e210fa0fabdf13dbe66d77b7fb277c4460ba43f0..31e73db14ccf1f06998329c92674f3f348a0a924 100644 (file)
@@ -35,11 +35,9 @@ import {
 import type {
   IWorker,
   IWorkerNode,
-  TaskStatistics,
   WorkerInfo,
   WorkerNodeEventDetail,
-  WorkerType,
-  WorkerUsage
+  WorkerType
 } from './worker.js'
 import {
   Measurements,
@@ -212,13 +210,13 @@ export abstract class AbstractPool<
   private checkPoolOptions (opts: PoolOptions<Worker>): void {
     if (isPlainObject(opts)) {
       this.opts.startWorkers = opts.startWorkers ?? true
-      checkValidWorkerChoiceStrategy(
-        opts.workerChoiceStrategy as WorkerChoiceStrategy
-      )
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      checkValidWorkerChoiceStrategy(opts.workerChoiceStrategy!)
       this.opts.workerChoiceStrategy =
         opts.workerChoiceStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN
       this.checkValidWorkerChoiceStrategyOptions(
-        opts.workerChoiceStrategyOptions as WorkerChoiceStrategyOptions
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        opts.workerChoiceStrategyOptions!
       )
       if (opts.workerChoiceStrategyOptions != null) {
         this.opts.workerChoiceStrategyOptions = opts.workerChoiceStrategyOptions
@@ -227,9 +225,11 @@ export abstract class AbstractPool<
       this.opts.enableEvents = opts.enableEvents ?? true
       this.opts.enableTasksQueue = opts.enableTasksQueue ?? false
       if (this.opts.enableTasksQueue) {
-        checkValidTasksQueueOptions(opts.tasksQueueOptions as TasksQueueOptions)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        checkValidTasksQueueOptions(opts.tasksQueueOptions!)
         this.opts.tasksQueueOptions = this.buildTasksQueueOptions(
-          opts.tasksQueueOptions as TasksQueueOptions
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          opts.tasksQueueOptions!
         )
       }
     } else {
@@ -283,7 +283,8 @@ export abstract class AbstractPool<
       worker: this.worker,
       started: this.started,
       ready: this.ready,
-      strategy: this.opts.workerChoiceStrategy as WorkerChoiceStrategy,
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      strategy: this.opts.workerChoiceStrategy!,
       minSize: this.minimumNumberOfWorkers,
       maxSize: this.maximumNumberOfWorkers ?? this.minimumNumberOfWorkers,
       ...(this.workerChoiceStrategyContext?.getTaskStatisticsRequirements()
@@ -559,7 +560,8 @@ export abstract class AbstractPool<
       this.flushTasksQueues()
     }
     this.opts.enableTasksQueue = enable
-    this.setTasksQueueOptions(tasksQueueOptions as TasksQueueOptions)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    this.setTasksQueueOptions(tasksQueueOptions!)
   }
 
   /** @inheritDoc */
@@ -568,7 +570,8 @@ export abstract class AbstractPool<
       checkValidTasksQueueOptions(tasksQueueOptions)
       this.opts.tasksQueueOptions =
         this.buildTasksQueueOptions(tasksQueueOptions)
-      this.setTasksQueueSize(this.opts.tasksQueueOptions.size as number)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.setTasksQueueSize(this.opts.tasksQueueOptions.size!)
       if (this.opts.tasksQueueOptions.taskStealing === true) {
         this.unsetTaskStealing()
         this.setTaskStealing()
@@ -670,7 +673,8 @@ export abstract class AbstractPool<
           workerNode =>
             workerNode.info.ready &&
             workerNode.usage.tasks.executing <
-              (this.opts.tasksQueueOptions?.concurrency as number)
+              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+              this.opts.tasksQueueOptions!.concurrency!
         ) === -1
       )
     }
@@ -686,7 +690,8 @@ export abstract class AbstractPool<
     if (this.opts.enableTasksQueue === true) {
       return (
         this.workerNodes[workerNodeKey].usage.tasks.executing >=
-        (this.opts.tasksQueueOptions?.concurrency as number)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.opts.tasksQueueOptions!.concurrency!
       )
     }
     return this.workerNodes[workerNodeKey].usage.tasks.executing > 0
@@ -701,7 +706,8 @@ export abstract class AbstractPool<
         message: MessageValue<Response>
       ): void => {
         this.checkMessageWorkerId(message)
-        const workerId = this.getWorkerInfo(workerNodeKey).id as number
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        const workerId = this.getWorkerInfo(workerNodeKey).id!
         if (
           message.taskFunctionOperationStatus != null &&
           message.workerId === workerId
@@ -713,8 +719,10 @@ export abstract class AbstractPool<
               new Error(
                 `Task function operation '${
                   message.taskFunctionOperation as string
+                  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
                 }' failed on worker ${message.workerId} with error: '${
-                  message.workerError?.message as string
+                  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+                  message.workerError!.message
                 }'`
               )
             )
@@ -763,10 +771,11 @@ export abstract class AbstractPool<
                 new Error(
                   `Task function operation '${
                     message.taskFunctionOperation as string
-                  }' failed on worker ${
-                    errorResponse?.workerId as number
-                  } with error: '${
-                    errorResponse?.workerError?.message as string
+                    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+                  }' failed on worker ${errorResponse!
+                    .workerId!} with error: '${
+                    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+                    errorResponse!.workerError!.message
                   }'`
                 )
               )
@@ -871,7 +880,8 @@ export abstract class AbstractPool<
     return (
       this.tasksQueueSize(workerNodeKey) === 0 &&
       this.workerNodes[workerNodeKey].usage.tasks.executing <
-        (this.opts.tasksQueueOptions?.concurrency as number)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.opts.tasksQueueOptions!.concurrency!
     )
   }
 
@@ -916,7 +926,8 @@ export abstract class AbstractPool<
         timestamp,
         taskId: randomUUID()
       }
-      this.promiseResponseMap.set(task.taskId as string, {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.promiseResponseMap.set(task.taskId!, {
         resolve,
         reject,
         workerNodeKey,
@@ -1002,9 +1013,8 @@ export abstract class AbstractPool<
         } else if (message.kill === 'failure') {
           reject(
             new Error(
-              `Kill message handling failed on worker ${
-                message.workerId as number
-              }`
+              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+              `Kill message handling failed on worker ${message.workerId!}`
             )
           )
         }
@@ -1074,13 +1084,15 @@ export abstract class AbstractPool<
     }
     if (
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
-      this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(
-        task.name as string
-      ) != null
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(task.name!) !=
+        null
     ) {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       const taskFunctionWorkerUsage = this.workerNodes[
         workerNodeKey
-      ].getTaskFunctionWorkerUsage(task.name as string) as WorkerUsage
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      ].getTaskFunctionWorkerUsage(task.name!)!
       ++taskFunctionWorkerUsage.tasks.executing
       updateWaitTimeWorkerUsage(
         this.workerChoiceStrategyContext,
@@ -1120,14 +1132,15 @@ export abstract class AbstractPool<
     if (
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
       this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(
-        message.taskPerformance?.name as string
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        message.taskPerformance!.name
       ) != null
     ) {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       const taskFunctionWorkerUsage = this.workerNodes[
         workerNodeKey
-      ].getTaskFunctionWorkerUsage(
-        message.taskPerformance?.name as string
-      ) as WorkerUsage
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      ].getTaskFunctionWorkerUsage(message.taskPerformance!.name)!
       updateTaskStatisticsWorkerUsage(taskFunctionWorkerUsage, message)
       updateRunTimeWorkerUsage(
         this.workerChoiceStrategyContext,
@@ -1436,7 +1449,8 @@ export abstract class AbstractPool<
       )
       this.handleTask(
         destinationWorkerNodeKey,
-        this.dequeueTask(workerNodeKey) as Task<Data>
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.dequeueTask(workerNodeKey)!
       )
     }
   }
@@ -1453,9 +1467,9 @@ export abstract class AbstractPool<
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
       workerNode.getTaskFunctionWorkerUsage(taskName) != null
     ) {
-      const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
-        taskName
-      ) as WorkerUsage
+      const taskFunctionWorkerUsage =
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        workerNode.getTaskFunctionWorkerUsage(taskName)!
       ++taskFunctionWorkerUsage.tasks.stolen
     }
   }
@@ -1478,9 +1492,9 @@ export abstract class AbstractPool<
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
       workerNode.getTaskFunctionWorkerUsage(taskName) != null
     ) {
-      const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
-        taskName
-      ) as WorkerUsage
+      const taskFunctionWorkerUsage =
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        workerNode.getTaskFunctionWorkerUsage(taskName)!
       ++taskFunctionWorkerUsage.tasks.sequentiallyStolen
     }
   }
@@ -1503,9 +1517,9 @@ export abstract class AbstractPool<
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
       workerNode.getTaskFunctionWorkerUsage(taskName) != null
     ) {
-      const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
-        taskName
-      ) as WorkerUsage
+      const taskFunctionWorkerUsage =
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        workerNode.getTaskFunctionWorkerUsage(taskName)!
       taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0
     }
   }
@@ -1522,8 +1536,8 @@ export abstract class AbstractPool<
     }
     if (
       this.cannotStealTask() ||
-      (this.info.stealingWorkerNodes as number) >
-        Math.floor(this.workerNodes.length / 2)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.info.stealingWorkerNodes! > Math.floor(this.workerNodes.length / 2)
     ) {
       if (previousStolenTask != null) {
         this.getWorkerInfo(workerNodeKey).stealing = false
@@ -1538,8 +1552,9 @@ export abstract class AbstractPool<
         this.tasksQueueSize(workerNodeKey) > 0)
     ) {
       this.getWorkerInfo(workerNodeKey).stealing = false
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       for (const taskName of this.workerNodes[workerNodeKey].info
-        .taskFunctionNames as string[]) {
+        .taskFunctionNames!) {
         this.resetTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
           workerNodeKey,
           taskName
@@ -1554,10 +1569,11 @@ export abstract class AbstractPool<
       this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
       stolenTask != null
     ) {
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       const taskFunctionTasksWorkerUsage = this.workerNodes[
         workerNodeKey
-      ].getTaskFunctionWorkerUsage(stolenTask.name as string)
-        ?.tasks as TaskStatistics
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      ].getTaskFunctionWorkerUsage(stolenTask.name!)!.tasks
       if (
         taskFunctionTasksWorkerUsage.sequentiallyStolen === 0 ||
         (previousStolenTask != null &&
@@ -1566,12 +1582,14 @@ export abstract class AbstractPool<
       ) {
         this.updateTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
           workerNodeKey,
-          stolenTask.name as string
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          stolenTask.name!
         )
       } else {
         this.resetTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
           workerNodeKey,
-          stolenTask.name as string
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          stolenTask.name!
         )
       }
     }
@@ -1600,13 +1618,12 @@ export abstract class AbstractPool<
         sourceWorkerNode.usage.tasks.queued > 0
     )
     if (sourceWorkerNode != null) {
-      const task = sourceWorkerNode.popTask() as Task<Data>
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      const task = sourceWorkerNode.popTask()!
       this.handleTask(workerNodeKey, task)
       this.updateTaskSequentiallyStolenStatisticsWorkerUsage(workerNodeKey)
-      this.updateTaskStolenStatisticsWorkerUsage(
-        workerNodeKey,
-        task.name as string
-      )
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.updateTaskStolenStatisticsWorkerUsage(workerNodeKey, task.name!)
       return task
     }
   }
@@ -1616,14 +1633,15 @@ export abstract class AbstractPool<
   ): void => {
     if (
       this.cannotStealTask() ||
-      (this.info.stealingWorkerNodes as number) >
-        Math.floor(this.workerNodes.length / 2)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.info.stealingWorkerNodes! > Math.floor(this.workerNodes.length / 2)
     ) {
       return
     }
     const { workerId } = eventDetail
     const sizeOffset = 1
-    if ((this.opts.tasksQueueOptions?.size as number) <= sizeOffset) {
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    if (this.opts.tasksQueueOptions!.size! <= sizeOffset) {
       return
     }
     const sourceWorkerNode =
@@ -1641,15 +1659,15 @@ export abstract class AbstractPool<
         !workerNode.info.stealing &&
         workerNode.info.id !== workerId &&
         workerNode.usage.tasks.queued <
-          (this.opts.tasksQueueOptions?.size as number) - sizeOffset
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          this.opts.tasksQueueOptions!.size! - sizeOffset
       ) {
         this.getWorkerInfo(workerNodeKey).stealing = true
-        const task = sourceWorkerNode.popTask() as Task<Data>
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        const task = sourceWorkerNode.popTask()!
         this.handleTask(workerNodeKey, task)
-        this.updateTaskStolenStatisticsWorkerUsage(
-          workerNodeKey,
-          task.name as string
-        )
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        this.updateTaskStolenStatisticsWorkerUsage(workerNodeKey, task.name!)
         this.getWorkerInfo(workerNodeKey).stealing = false
       }
     }
@@ -1680,7 +1698,8 @@ export abstract class AbstractPool<
   private handleWorkerReadyResponse (message: MessageValue<Response>): void {
     const { workerId, ready, taskFunctionNames } = message
     if (ready === false) {
-      throw new Error(`Worker ${workerId as number} failed to initialize`)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      throw new Error(`Worker ${workerId!} failed to initialize`)
     }
     const workerInfo = this.getWorkerInfo(
       this.getWorkerNodeKeyByWorkerId(workerId)
@@ -1695,7 +1714,8 @@ export abstract class AbstractPool<
 
   private handleTaskExecutionResponse (message: MessageValue<Response>): void {
     const { workerId, taskId, workerError, data } = message
-    const promiseResponse = this.promiseResponseMap.get(taskId as string)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    const promiseResponse = this.promiseResponseMap.get(taskId!)
     if (promiseResponse != null) {
       const { resolve, reject, workerNodeKey, asyncResource } = promiseResponse
       const workerNode = this.workerNodes[workerNodeKey]
@@ -1715,19 +1735,19 @@ export abstract class AbstractPool<
       }
       asyncResource?.emitDestroy()
       this.afterTaskExecutionHook(workerNodeKey, message)
-      this.promiseResponseMap.delete(taskId as string)
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.promiseResponseMap.delete(taskId!)
       workerNode?.emit('taskFinished', taskId)
       if (this.opts.enableTasksQueue === true && !this.destroying) {
         const workerNodeTasksUsage = workerNode.usage.tasks
         if (
           this.tasksQueueSize(workerNodeKey) > 0 &&
           workerNodeTasksUsage.executing <
-            (this.opts.tasksQueueOptions?.concurrency as number)
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            this.opts.tasksQueueOptions!.concurrency!
         ) {
-          this.executeTask(
-            workerNodeKey,
-            this.dequeueTask(workerNodeKey) as Task<Data>
-          )
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          this.executeTask(workerNodeKey, this.dequeueTask(workerNodeKey)!)
         }
         if (
           workerNodeTasksUsage.executing === 0 &&
@@ -1735,7 +1755,8 @@ export abstract class AbstractPool<
           workerNodeTasksUsage.sequentiallyStolen === 0
         ) {
           workerNode.emit('idleWorkerNode', {
-            workerId: workerId as number,
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            workerId: workerId!,
             workerNodeKey
           })
         }
@@ -1875,10 +1896,8 @@ export abstract class AbstractPool<
   protected flushTasksQueue (workerNodeKey: number): number {
     let flushedTasks = 0
     while (this.tasksQueueSize(workerNodeKey) > 0) {
-      this.executeTask(
-        workerNodeKey,
-        this.dequeueTask(workerNodeKey) as Task<Data>
-      )
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.executeTask(workerNodeKey, this.dequeueTask(workerNodeKey)!)
       ++flushedTasks
     }
     this.workerNodes[workerNodeKey].clearTasksQueue()
index 311d5c9d9393157205d03e5029f5515d7ba9a46b..8ef11c00d8975f38cded441e0ac4a42a639e9116 100644 (file)
@@ -34,7 +34,8 @@ export class DynamicClusterPool<
     super(min, filePath, opts, max)
     checkDynamicPoolSize(
       this.minimumNumberOfWorkers,
-      this.maximumNumberOfWorkers as number
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.maximumNumberOfWorkers!
     )
   }
 
index 3b45dc17e005f9495ea73a05c6abef478fccb2de..aa731562011507f59b84cce1f7088be68924e0b0 100644 (file)
@@ -54,7 +54,8 @@ export class FixedClusterPool<
   ): void {
     this.workerNodes[workerNodeKey].worker.send({
       ...message,
-      workerId: this.getWorkerInfo(workerNodeKey).id as number
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      workerId: this.getWorkerInfo(workerNodeKey).id!
     })
   }
 
index 49b7c58442572b9dfd1d2aee691238b152ce54ca..daed6b70093f6d3a3508bb8034b6935c0c17f729 100644 (file)
@@ -70,15 +70,18 @@ export abstract class AbstractWorkerChoiceStrategy<
   ): void {
     this.toggleMedianMeasurementStatisticsRequirements(
       this.taskStatisticsRequirements.runTime,
-      opts.runTime?.median as boolean
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      opts.runTime!.median
     )
     this.toggleMedianMeasurementStatisticsRequirements(
       this.taskStatisticsRequirements.waitTime,
-      opts.waitTime?.median as boolean
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      opts.waitTime!.median
     )
     this.toggleMedianMeasurementStatisticsRequirements(
       this.taskStatisticsRequirements.elu,
-      opts.elu?.median as boolean
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      opts.elu!.median
     )
   }
 
@@ -141,7 +144,8 @@ export abstract class AbstractWorkerChoiceStrategy<
    * Check the next worker node readiness.
    */
   protected checkNextWorkerNodeReadiness (): void {
-    if (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number)) {
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
       delete this.nextWorkerNodeKey
     }
   }
index c6b87ade001759855115117d155a170a2e104c08..e8f9cc619f6a7f0d8ffc596332e27a9159c72e01 100644 (file)
@@ -1,6 +1,6 @@
 import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
 import type { IPool } from '../pool.js'
-import type { IWorker, StrategyData } from '../worker.js'
+import type { IWorker } from '../worker.js'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
 import {
   type IWorkerChoiceStrategy,
@@ -87,9 +87,10 @@ export class FairShareWorkerChoiceStrategy<
           }
         }
         return this.isWorkerNodeReady(workerNodeKey) &&
-          (workerNode.strategyData.virtualTaskEndTimestamp as number) <
-            ((workerNodes[minWorkerNodeKey].strategyData as StrategyData)
-              .virtualTaskEndTimestamp as number)
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          workerNode.strategyData.virtualTaskEndTimestamp! <
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            workerNodes[minWorkerNodeKey].strategyData!.virtualTaskEndTimestamp!
           ? workerNodeKey
           : minWorkerNodeKey
       },
@@ -131,7 +132,8 @@ export class FairShareWorkerChoiceStrategy<
         ?.virtualTaskEndTimestamp
     const now = performance.now()
     return now < (virtualTaskEndTimestamp ?? -Infinity)
-      ? (virtualTaskEndTimestamp as number)
+      ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      virtualTaskEndTimestamp!
       : now
   }
 }
index db439f0209c2ddf21cbe081f3d2b72138453545b..fe4b48833ee98459880878c91a82204cac8408f5 100644 (file)
@@ -94,7 +94,8 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
         ) {
           this.workerNodeVirtualTaskRunTime = 0
         }
-        const workerWeight = this.opts.weights?.[workerNodeKey] as number
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        const workerWeight = this.opts.weights![workerNodeKey]!
         if (
           this.isWorkerNodeReady(workerNodeKey) &&
           workerWeight >= this.roundWeights[roundIndex] &&
@@ -156,7 +157,8 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
   private getRoundWeights (): number[] {
     return [
       ...new Set(
-        Object.values(this.opts.weights as Record<number, number>)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        Object.values(this.opts.weights!)
           .slice()
           .sort((a, b) => a - b)
       )
index 4b7eac7a17d3f2f4963a21d3f7db429bc73a21b9..5ccc9c320ac6e09cce290c8a848c4e0ebdb60006 100644 (file)
@@ -89,9 +89,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private weightedRoundRobinNextWorkerNodeKey (): number | undefined {
-    const workerWeight = this.opts.weights?.[
-      this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
-    ] as number
+    const workerWeight =
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.opts.weights![this.nextWorkerNodeKey ?? this.previousWorkerNodeKey]!
     if (this.workerNodeVirtualTaskRunTime < workerWeight) {
       this.workerNodeVirtualTaskRunTime =
         this.workerNodeVirtualTaskRunTime +
index d76ee8afef2a15668fe1e921be6e6ac365df3a92..330e584d4a1fd74e0878bb820afb538d2c7a72ec 100644 (file)
@@ -115,11 +115,9 @@ export class WorkerChoiceStrategyContext<
    * @returns The strategy policy.
    */
   public getStrategyPolicy (): StrategyPolicy {
-    return (
-      this.workerChoiceStrategies.get(
-        this.workerChoiceStrategy
-      ) as IWorkerChoiceStrategy
-    ).strategyPolicy
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    return this.workerChoiceStrategies.get(this.workerChoiceStrategy)!
+      .strategyPolicy
   }
 
   /**
@@ -128,11 +126,9 @@ export class WorkerChoiceStrategyContext<
    * @returns The task statistics requirements.
    */
   public getTaskStatisticsRequirements (): TaskStatisticsRequirements {
-    return (
-      this.workerChoiceStrategies.get(
-        this.workerChoiceStrategy
-      ) as IWorkerChoiceStrategy
-    ).taskStatisticsRequirements
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    return this.workerChoiceStrategies.get(this.workerChoiceStrategy)!
+      .taskStatisticsRequirements
   }
 
   /**
@@ -155,11 +151,10 @@ export class WorkerChoiceStrategyContext<
    * @returns `true` if the update is successful, `false` otherwise.
    */
   public update (workerNodeKey: number): boolean {
-    return (
-      this.workerChoiceStrategies.get(
-        this.workerChoiceStrategy
-      ) as IWorkerChoiceStrategy
-    ).update(workerNodeKey)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    return this.workerChoiceStrategies
+      .get(this.workerChoiceStrategy)!
+      .update(workerNodeKey)
   }
 
   /**
@@ -169,9 +164,10 @@ export class WorkerChoiceStrategyContext<
    * @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined.
    */
   public execute (): number {
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const workerChoiceStrategy = this.workerChoiceStrategies.get(
       this.workerChoiceStrategy
-    ) as IWorkerChoiceStrategy
+    )!
     if (!workerChoiceStrategy.hasPoolWorkerNodesReady()) {
       return this.execute()
     }
@@ -195,10 +191,8 @@ export class WorkerChoiceStrategyContext<
         retriesCount++
       }
       chooseCount++
-    } while (
-      workerNodeKey == null &&
-      retriesCount < (this.opts?.retries as number)
-    )
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    } while (workerNodeKey == null && retriesCount < this.opts!.retries!)
     if (workerNodeKey == null) {
       throw new Error(
         `Worker node key chosen is null or undefined after ${retriesCount} retries`
@@ -214,11 +208,10 @@ export class WorkerChoiceStrategyContext<
    * @returns `true` if the removal is successful, `false` otherwise.
    */
   public remove (workerNodeKey: number): boolean {
-    return (
-      this.workerChoiceStrategies.get(
-        this.workerChoiceStrategy
-      ) as IWorkerChoiceStrategy
-    ).remove(workerNodeKey)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    return this.workerChoiceStrategies
+      .get(this.workerChoiceStrategy)!
+      .remove(workerNodeKey)
   }
 
   /**
index 2fc360817d2b7bab3e634365b03ca9b541c76715..2a7d0149392a4295ec8e32717c68a84a140cef53 100644 (file)
@@ -34,7 +34,8 @@ export class DynamicThreadPool<
     super(min, filePath, opts, max)
     checkDynamicPoolSize(
       this.minimumNumberOfWorkers,
-      this.maximumNumberOfWorkers as number
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.maximumNumberOfWorkers!
     )
   }
 
index 11a24e2780dc445a37cdca15808eb71f95dd5bd9..c4256bf3b2213d8d7a6a60d7df8a95447576b888 100644 (file)
@@ -1,5 +1,4 @@
 import {
-  type MessageChannel,
   type MessagePort,
   type TransferListItem,
   type Worker,
@@ -63,8 +62,8 @@ export class FixedThreadPool<
   /** @inheritDoc */
   protected sendStartupMessageToWorker (workerNodeKey: number): void {
     const workerNode = this.workerNodes[workerNodeKey]
-    const port2: MessagePort = (workerNode.messageChannel as MessageChannel)
-      .port2
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    const port2: MessagePort = workerNode.messageChannel!.port2
     workerNode.worker.postMessage(
       {
         ready: false,
index bf2600d57782873bea28f50f413a7de945a35b35..6a5881da097bbbd727806a024edf9c6ab06eb7c3 100644 (file)
@@ -80,7 +80,8 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
     const tasksQueueSize = this.tasksQueue.push(task)
     if (this.hasBackPressure() && !this.onBackPressureStarted) {
       this.onBackPressureStarted = true
-      this.emit('backPressure', { workerId: this.info.id as number })
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.emit('backPressure', { workerId: this.info.id! })
       this.onBackPressureStarted = false
     }
     return tasksQueueSize
@@ -91,7 +92,8 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
     const tasksQueueSize = this.tasksQueue.unshift(task)
     if (this.hasBackPressure() && !this.onBackPressureStarted) {
       this.onBackPressureStarted = true
-      this.emit('backPressure', { workerId: this.info.id as number })
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.emit('backPressure', { workerId: this.info.id! })
       this.onBackPressureStarted = false
     }
     return tasksQueueSize
@@ -212,7 +214,8 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
   private initWorkerInfo (worker: Worker): WorkerInfo {
     return {
       id: getWorkerId(worker),
-      type: getWorkerType(worker) as WorkerType,
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      type: getWorkerType(worker)!,
       dynamic: false,
       ready: false,
       stealing: false
@@ -263,7 +266,8 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
       for (const task of this.tasksQueue) {
         if (
           (task.name === DEFAULT_TASK_NAME &&
-            name === (this.info.taskFunctionNames as string[])[1]) ||
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            name === this.info.taskFunctionNames![1]) ||
           (task.name !== DEFAULT_TASK_NAME && name === task.name)
         ) {
           ++taskFunctionQueueSize
index 81523d8ca964f5af19308c65e99f36de618699a9..2359758dc72c2a362b60e513890664731fdc7fea 100644 (file)
@@ -277,10 +277,8 @@ export abstract class AbstractWorker<
           'Cannot set the default task function to a non-existing task function'
         )
       }
-      this.taskFunctions.set(
-        DEFAULT_TASK_NAME,
-        this.taskFunctions.get(name) as TaskFunction<Data, Response>
-      )
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      this.taskFunctions.set(DEFAULT_TASK_NAME, this.taskFunctions.get(name)!)
       this.sendTaskFunctionNamesToMainWorker()
       return { status: true }
     } catch (error) {
@@ -328,19 +326,22 @@ export abstract class AbstractWorker<
     switch (taskFunctionOperation) {
       case 'add':
         response = this.addTaskFunction(
-          taskFunctionName as string,
-          // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
-          new Function(`return ${taskFunction as string}`)() as TaskFunction<
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          taskFunctionName!,
+          // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func, @typescript-eslint/no-non-null-assertion
+          new Function(`return ${taskFunction!}`)() as TaskFunction<
           Data,
           Response
           >
         )
         break
       case 'remove':
-        response = this.removeTaskFunction(taskFunctionName as string)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        response = this.removeTaskFunction(taskFunctionName!)
         break
       case 'default':
-        response = this.setDefaultTaskFunction(taskFunctionName as string)
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        response = this.setDefaultTaskFunction(taskFunctionName!)
         break
       default:
         response = { status: false, error: new Error('Unknown task operation') }
@@ -353,7 +354,8 @@ export abstract class AbstractWorker<
       ...(!response.status &&
         response?.error != null && {
         workerError: {
-          name: taskFunctionName as string,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          name: taskFunctionName!,
           message: this.handleError(response.error as Error | string)
         }
       })
@@ -488,8 +490,10 @@ export abstract class AbstractWorker<
     if (!this.taskFunctions.has(taskFunctionName)) {
       this.sendToMainWorker({
         workerError: {
-          name: name as string,
-          message: `Task function '${name as string}' not found`,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          name: name!,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          message: `Task function '${name!}' not found`,
           data
         },
         taskId
@@ -527,7 +531,8 @@ export abstract class AbstractWorker<
     } catch (error) {
       this.sendToMainWorker({
         workerError: {
-          name: name as string,
+          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+          name: name!,
           message: this.handleError(error as Error | string),
           data
         },
@@ -563,7 +568,8 @@ export abstract class AbstractWorker<
       .catch(error => {
         this.sendToMainWorker({
           workerError: {
-            name: name as string,
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            name: name!,
             message: this.handleError(error as Error | string),
             data
           },
index fa810c7e66451ba978320ab887c8073c74214a88..05fe25343acc736f53085947e551e3869486bf5f 100644 (file)
@@ -32,7 +32,8 @@ export class ClusterWorker<
     taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
     opts: WorkerOptions = {}
   ) {
-    super(cluster.isPrimary, cluster.worker as Worker, taskFunctions, opts)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    super(cluster.isPrimary, cluster.worker!, taskFunctions, opts)
   }
 
   /** @inheritDoc */
index 2a50249f7bbd406ad6789d80167bace6cb009dc6..7f3cd950a992269fb7917b7eda296419a501b6f8 100644 (file)
@@ -42,7 +42,8 @@ export class ThreadWorker<
     taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
     opts: WorkerOptions = {}
   ) {
-    super(isMainThread, parentPort as MessagePort, taskFunctions, opts)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    super(isMainThread, parentPort!, taskFunctions, opts)
   }
 
   /** @inheritDoc */