fix: readd ThreadPoolOptions and ClusterPoolOptions TS type aliases to PoolOptions
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Dec 2023 12:10:42 +0000 (13:10 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 22 Dec 2023 12:10:42 +0000 (13:10 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
docs/api.md
examples/typescript/http-server-pool/express-hybrid/src/types.ts
examples/typescript/http-server-pool/fastify-hybrid/src/types.ts
examples/typescript/http-server-pool/fastify-worker_threads/src/types.ts
examples/typescript/websocket-server-pool/ws-hybrid/src/types.ts
src/index.ts
src/pools/cluster/dynamic.ts
src/pools/cluster/fixed.ts
src/pools/thread/dynamic.ts
src/pools/thread/fixed.ts

index 786b8867ac4a304b650573f91e7dd7a5e42712de..24db9a71fc782729f9c2895cb4719ad13c6e61d9 100644 (file)
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Changed
+
+- Readd ThreadPoolOptions and ClusterPoolOptions TS type aliases to PoolOptions.
+
 ## [3.1.8] - 2023-12-21
 
 ### Fixed
index bd5ace7a7cc19df75d509e0c7bcf722a7a14f095..1a881ba59d1f6eea52f8630f3f872d9269c774bd 100644 (file)
@@ -13,7 +13,7 @@
   - [`pool.removeTaskFunction(name)`](#poolremovetaskfunctionname)
   - [`pool.listTaskFunctionNames()`](#poollisttaskfunctionnames)
   - [`pool.setDefaultTaskFunction(name)`](#poolsetdefaulttaskfunctionname)
-  - [`PoolOptions`](#pooloptions)
+  - [`Pool options`](#pool-options)
 - [Worker](#worker)
   - [`class YourWorker extends ThreadWorker/ClusterWorker`](#class-yourworker-extends-threadworkerclusterworker)
     - [`YourWorker.hasTaskFunction(name)`](#yourworkerhastaskfunctionname)
@@ -82,7 +82,7 @@ This method is available on both pool implementations and returns an array of th
 
 This method is available on both pool implementations and returns a boolean promise.
 
-### `PoolOptions`
+### `Pool options`
 
 An object with these properties:
 
index 293c57d74115ed635d338b6444cf4f1ceab2ea59..76a9133e60f1c7d462bdfaf52b7eb54d328b218c 100644 (file)
@@ -1,7 +1,6 @@
-import type { Worker } from 'node:worker_threads'
-import type { PoolOptions } from 'poolifier'
+import type { ThreadPoolOptions } from 'poolifier'
 
-export interface ClusterWorkerData extends PoolOptions<Worker> {
+export interface ClusterWorkerData extends ThreadPoolOptions {
   port: number
   workerFile: string
   minWorkers?: number
index 137f4a98e22aa076085ae405455f1c4b28f82327..179ac65edd4cd708c4babe4728599a961fe9c1a1 100644 (file)
@@ -1,5 +1,4 @@
-import type { Worker } from 'node:worker_threads'
-import type { PoolOptions } from 'poolifier'
+import type { ThreadPoolOptions } from 'poolifier'
 
 export interface ClusterWorkerData extends FastifyPoolifierOptions {
   port: number
@@ -22,7 +21,7 @@ export interface ThreadWorkerResponse<T = unknown> {
   data: T
 }
 
-export interface FastifyPoolifierOptions extends PoolOptions<Worker> {
+export interface FastifyPoolifierOptions extends ThreadPoolOptions {
   workerFile: string
   minWorkers?: number
   maxWorkers?: number
index 0c92e5b24a89db14ac60c58880d8140290d9a195..97c2c540df9edbf44a01c01f6b8517c3d04a4d73 100644 (file)
@@ -1,5 +1,4 @@
-import type { Worker } from 'node:worker_threads'
-import type { PoolOptions } from 'poolifier'
+import type { ThreadPoolOptions } from 'poolifier'
 
 export interface BodyPayload {
   number?: number
@@ -13,7 +12,7 @@ export interface WorkerResponse<T = unknown> {
   body: T
 }
 
-export interface FastifyPoolifierOptions extends PoolOptions<Worker> {
+export interface FastifyPoolifierOptions extends ThreadPoolOptions {
   workerFile: string
   minWorkers?: number
   maxWorkers?: number
index ac3ad1ec33329c5b508b5114e5d1a7b5ece01686..d52dbf2396569595aae7918775f208bdcd54154f 100644 (file)
@@ -1,5 +1,4 @@
-import type { Worker } from 'node:worker_threads'
-import type { PoolOptions } from 'poolifier'
+import type { ThreadPoolOptions } from 'poolifier'
 
 export enum MessageType {
   echo = 'echo',
@@ -15,7 +14,7 @@ export interface DataPayload {
   number?: number
 }
 
-export interface ClusterWorkerData extends PoolOptions<Worker> {
+export interface ClusterWorkerData extends ThreadPoolOptions {
   port: number
   workerFile: string
   minWorkers?: number
index 6c9aa47e2092752bdadd7f409480ef8e4ce20128..880fdcbac253caac0e4055f52102d8bdb3a52854 100644 (file)
@@ -1,6 +1,7 @@
 export type { AbstractPool } from './pools/abstract-pool'
 export { DynamicClusterPool } from './pools/cluster/dynamic'
 export { FixedClusterPool } from './pools/cluster/fixed'
+export type { ClusterPoolOptions } from './pools/cluster/fixed'
 export { PoolEvents, PoolTypes } from './pools/pool'
 export type {
   IPool,
@@ -34,6 +35,7 @@ export {
 } from './pools/selection-strategies/selection-strategies-types'
 export type {
   IWorkerChoiceStrategy,
+  InternalWorkerChoiceStrategyOptions,
   Measurement,
   MeasurementOptions,
   MeasurementStatisticsRequirements,
@@ -45,6 +47,7 @@ export type {
 export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context'
 export { DynamicThreadPool } from './pools/thread/dynamic'
 export { FixedThreadPool } from './pools/thread/fixed'
+export type { ThreadPoolOptions } from './pools/thread/fixed'
 export type { AbstractWorker } from './worker/abstract-worker'
 export { ClusterWorker } from './worker/cluster-worker'
 export { ThreadWorker } from './worker/thread-worker'
index 9f2f0dd95130a37d4bf010b071dbcc30271ab9ac..9636b423915fc670c9b42f24680cee131f343c3a 100644 (file)
@@ -1,7 +1,6 @@
-import { type Worker } from 'node:cluster'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
 import { checkDynamicPoolSize } from '../utils'
-import { FixedClusterPool } from './fixed'
+import { type PoolType, PoolTypes } from '../pool'
+import { type ClusterPoolOptions, FixedClusterPool } from './fixed'
 
 /**
  * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
@@ -30,7 +29,7 @@ export class DynamicClusterPool<
     min: number,
     max: number,
     filePath: string,
-    opts: PoolOptions<Worker> = {}
+    opts: ClusterPoolOptions = {}
   ) {
     super(min, filePath, opts, max)
     checkDynamicPoolSize(
index d6481be720914c2af14c56bf0182030aa0a456da..545238b0136fc5f0b1ae8d4c43710a302d087f8d 100644 (file)
@@ -4,6 +4,11 @@ import { AbstractPool } from '../abstract-pool'
 import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
 import { type WorkerType, WorkerTypes } from '../worker'
 
+/**
+ * Options for a poolifier cluster pool.
+ */
+export type ClusterPoolOptions = PoolOptions<Worker>
+
 /**
  * A cluster pool with a fixed number of workers.
  *
@@ -26,7 +31,7 @@ export class FixedClusterPool<
   public constructor (
     numberOfWorkers: number,
     filePath: string,
-    opts: PoolOptions<Worker> = {},
+    opts: ClusterPoolOptions = {},
     maximumNumberOfWorkers?: number
   ) {
     super(numberOfWorkers, filePath, opts, maximumNumberOfWorkers)
index b0a22346690bd36c471b6b45c844af8ffae098ea..cd9d23253a040f44070da2fe0b0504da31aeb283 100644 (file)
@@ -1,7 +1,6 @@
-import { type Worker } from 'node:worker_threads'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
+import { type PoolType, PoolTypes } from '../pool'
 import { checkDynamicPoolSize } from '../utils'
-import { FixedThreadPool } from './fixed'
+import { FixedThreadPool, type ThreadPoolOptions } from './fixed'
 
 /**
  * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
@@ -30,7 +29,7 @@ export class DynamicThreadPool<
     min: number,
     max: number,
     filePath: string,
-    opts: PoolOptions<Worker> = {}
+    opts: ThreadPoolOptions = {}
   ) {
     super(min, filePath, opts, max)
     checkDynamicPoolSize(
index d2f4df8e43f8fe0a905e115510c0c22424891313..13df2b5c602372fdde184989c84e8b3980aad8cf 100644 (file)
@@ -10,6 +10,11 @@ import { AbstractPool } from '../abstract-pool'
 import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
 import { type WorkerType, WorkerTypes } from '../worker'
 
+/**
+ * Options for a poolifier thread pool.
+ */
+export type ThreadPoolOptions = PoolOptions<Worker>
+
 /**
  * A thread pool with a fixed number of threads.
  *
@@ -32,7 +37,7 @@ export class FixedThreadPool<
   public constructor (
     numberOfThreads: number,
     filePath: string,
-    opts: PoolOptions<Worker> = {},
+    opts: ThreadPoolOptions = {},
     maximumNumberOfThreads?: number
   ) {
     super(numberOfThreads, filePath, opts, maximumNumberOfThreads)