From 2889bd70182e9e42c75d686ece3c288307e01d4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 22 Dec 2023 13:10:42 +0100 Subject: [PATCH] fix: readd ThreadPoolOptions and ClusterPoolOptions TS type aliases to PoolOptions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 4 ++++ docs/api.md | 4 ++-- .../http-server-pool/express-hybrid/src/types.ts | 5 ++--- .../http-server-pool/fastify-hybrid/src/types.ts | 5 ++--- .../http-server-pool/fastify-worker_threads/src/types.ts | 5 ++--- .../websocket-server-pool/ws-hybrid/src/types.ts | 5 ++--- src/index.ts | 3 +++ src/pools/cluster/dynamic.ts | 7 +++---- src/pools/cluster/fixed.ts | 7 ++++++- src/pools/thread/dynamic.ts | 7 +++---- src/pools/thread/fixed.ts | 7 ++++++- 11 files changed, 35 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 786b8867..24db9a71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/api.md b/docs/api.md index bd5ace7a..1a881ba5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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: diff --git a/examples/typescript/http-server-pool/express-hybrid/src/types.ts b/examples/typescript/http-server-pool/express-hybrid/src/types.ts index 293c57d7..76a9133e 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/types.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/types.ts @@ -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 { +export interface ClusterWorkerData extends ThreadPoolOptions { port: number workerFile: string minWorkers?: number diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/types.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/types.ts index 137f4a98..179ac65e 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/types.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/types.ts @@ -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 { data: T } -export interface FastifyPoolifierOptions extends PoolOptions { +export interface FastifyPoolifierOptions extends ThreadPoolOptions { workerFile: string minWorkers?: number maxWorkers?: number diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/types.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/types.ts index 0c92e5b2..97c2c540 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/types.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/types.ts @@ -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 { body: T } -export interface FastifyPoolifierOptions extends PoolOptions { +export interface FastifyPoolifierOptions extends ThreadPoolOptions { workerFile: string minWorkers?: number maxWorkers?: number diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/types.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/types.ts index ac3ad1ec..d52dbf23 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/types.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/types.ts @@ -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 { +export interface ClusterWorkerData extends ThreadPoolOptions { port: number workerFile: string minWorkers?: number diff --git a/src/index.ts b/src/index.ts index 6c9aa47e..880fdcba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 9f2f0dd9..9636b423 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -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 = {} + opts: ClusterPoolOptions = {} ) { super(min, filePath, opts, max) checkDynamicPoolSize( diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index d6481be7..545238b0 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -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 + /** * A cluster pool with a fixed number of workers. * @@ -26,7 +31,7 @@ export class FixedClusterPool< public constructor ( numberOfWorkers: number, filePath: string, - opts: PoolOptions = {}, + opts: ClusterPoolOptions = {}, maximumNumberOfWorkers?: number ) { super(numberOfWorkers, filePath, opts, maximumNumberOfWorkers) diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index b0a22346..cd9d2325 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -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 = {} + opts: ThreadPoolOptions = {} ) { super(min, filePath, opts, max) checkDynamicPoolSize( diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index d2f4df8e..13df2b5c 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -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 + /** * A thread pool with a fixed number of threads. * @@ -32,7 +37,7 @@ export class FixedThreadPool< public constructor ( numberOfThreads: number, filePath: string, - opts: PoolOptions = {}, + opts: ThreadPoolOptions = {}, maximumNumberOfThreads?: number ) { super(numberOfThreads, filePath, opts, maximumNumberOfThreads) -- 2.34.1