From ed6dd37f9e137cf659523d9d792f0171eedcb8ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 18 Mar 2023 18:08:55 +0100 Subject: [PATCH] fix: brown paper bag bug referencing the same object literal MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 9 +++++++++ src/pools/abstract-pool.ts | 4 ++-- src/pools/cluster/dynamic.ts | 3 +-- src/pools/cluster/fixed.ts | 3 +-- src/utils.ts | 5 ----- src/worker/cluster-worker.ts | 6 +----- src/worker/thread-worker.ts | 6 +----- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 431ebc04..6227f8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Introduce ESM module support along with CommonJS one. + +### Fixed + +- Fix brown paper bag bug referencing the same object literal. + ## [2.3.8] - 2023-03-18 ### Changed @@ -14,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Switch internal benchmarking code to benny. - Switch to TypeScript 5.x.x. - Switch rollup bundler plugins to core ones. +- Switch to TSDoc syntax. - Enforce conventional commits. ### Fixed diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 32b4d983..3cb6c1f7 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -2,7 +2,7 @@ import type { MessageValue, PromiseWorkerResponseWrapper } from '../utility-types' -import { EMPTY_FUNCTION, EMPTY_OBJECT_LITERAL } from '../utils' +import { EMPTY_FUNCTION } from '../utils' import { KillBehaviors, isKillBehavior } from '../worker/worker-options' import type { PoolOptions } from './pool' import { PoolEmitter } from './pool' @@ -208,7 +208,7 @@ export abstract class AbstractPool< const res = this.internalExecute(worker, this.nextMessageId) this.checkAndEmitBusy() this.sendToWorker(worker, { - data: data ?? (EMPTY_OBJECT_LITERAL as Data), + data, id: this.nextMessageId }) ++this.nextMessageId diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 513a73c5..8b8c5185 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -1,4 +1,3 @@ -import { EMPTY_OBJECT_LITERAL } from '../../utils' import { PoolType } from '../pool-internal' import type { ClusterPoolOptions } from './fixed' import { FixedClusterPool } from './fixed' @@ -30,7 +29,7 @@ export class DynamicClusterPool< min: number, protected readonly max: number, filePath: string, - opts: ClusterPoolOptions = EMPTY_OBJECT_LITERAL + opts: ClusterPoolOptions = {} ) { super(min, filePath, opts) } diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 092e9778..2e89b323 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,7 +1,6 @@ import type { ClusterSettings, Worker } from 'cluster' import cluster from 'cluster' import type { MessageValue } from '../../utility-types' -import { EMPTY_OBJECT_LITERAL } from '../../utils' import { AbstractPool } from '../abstract-pool' import type { PoolOptions } from '../pool' import { PoolType } from '../pool-internal' @@ -51,7 +50,7 @@ export class FixedClusterPool< public constructor ( numberOfWorkers: number, filePath: string, - public readonly opts: ClusterPoolOptions = EMPTY_OBJECT_LITERAL + public readonly opts: ClusterPoolOptions = {} ) { super(numberOfWorkers, filePath, opts) } diff --git a/src/utils.ts b/src/utils.ts index 753219c5..809ca38b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,8 +4,3 @@ export const EMPTY_FUNCTION: () => void = Object.freeze(() => { /* Intentionally empty */ }) - -/** - * An intentional empty object literal. - */ -export const EMPTY_OBJECT_LITERAL = {} diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index f551447e..4f5fbb6b 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -1,7 +1,6 @@ import type { Worker } from 'cluster' import cluster from 'cluster' import type { MessageValue } from '../utility-types' -import { EMPTY_OBJECT_LITERAL } from '../utils' import { AbstractWorker } from './abstract-worker' import type { WorkerOptions } from './worker-options' @@ -29,10 +28,7 @@ export class ClusterWorker< * @param fn - Function processed by the worker when the pool's `execution` function is invoked. * @param opts - Options for the worker. */ - public constructor ( - fn: (data: Data) => Response, - opts: WorkerOptions = EMPTY_OBJECT_LITERAL - ) { + public constructor (fn: (data: Data) => Response, opts: WorkerOptions = {}) { super( 'worker-cluster-pool:poolifier', cluster.isPrimary, diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 4ed85c29..a8424fbf 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -1,7 +1,6 @@ import type { MessagePort } from 'worker_threads' import { isMainThread, parentPort } from 'worker_threads' import type { MessageValue } from '../utility-types' -import { EMPTY_OBJECT_LITERAL } from '../utils' import { AbstractWorker } from './abstract-worker' import type { WorkerOptions } from './worker-options' @@ -29,10 +28,7 @@ export class ThreadWorker< * @param fn - Function processed by the worker when the pool's `execution` function is invoked. * @param opts - Options for the worker. */ - public constructor ( - fn: (data: Data) => Response, - opts: WorkerOptions = EMPTY_OBJECT_LITERAL - ) { + public constructor (fn: (data: Data) => Response, opts: WorkerOptions = {}) { super('worker-thread-pool:poolifier', isMainThread, fn, parentPort, opts) } -- 2.34.1