From 2845f2a5555247bbc4e5f6f1059d4f95405a49cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 4 Jul 2023 23:02:09 +0200 Subject: [PATCH] build: disable esModuleInterop from TS configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 8 ++++++++ src/pools/abstract-pool.ts | 8 ++++---- src/pools/pool.ts | 4 ++-- src/pools/worker.ts | 4 ---- src/utils.ts | 10 +++++----- tsconfig.json | 1 - 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e05c369..596b7f4d 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] +### Fixed + +- Recreate the right worker type on uncaught exception. + +### Added + +- Add minimum and maximum to internal measurement statistics. + ## [2.6.8] - 2023-07-03 ### Fixed diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index bfd0268a..95df53b2 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1,4 +1,4 @@ -import crypto from 'node:crypto' +import { randomUUID } from 'node:crypto' import { performance } from 'node:perf_hooks' import type { MessageValue, PromiseResponseWrapper } from '../utility-types' import { @@ -469,7 +469,7 @@ export abstract class AbstractPool< // eslint-disable-next-line @typescript-eslint/consistent-type-assertions data: data ?? ({} as Data), timestamp, - id: crypto.randomUUID() + id: randomUUID() } const res = new Promise((resolve, reject) => { this.promiseResponseMap.set(submittedTask.id as string, { @@ -938,10 +938,10 @@ export abstract class AbstractPool< private checkAndEmitEvents (): void { if (this.emitter != null) { if (this.busy) { - this.emitter?.emit(PoolEvents.busy, this.info) + this.emitter.emit(PoolEvents.busy, this.info) } if (this.type === PoolTypes.dynamic && this.full) { - this.emitter?.emit(PoolEvents.full, this.info) + this.emitter.emit(PoolEvents.full, this.info) } } } diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 22757f9a..bb28535b 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,4 +1,4 @@ -import EventEmitterAsyncResource from 'node:events' +import { EventEmitter } from 'node:events' import type { ErrorHandler, ExitHandler, @@ -47,7 +47,7 @@ export type WorkerType = keyof typeof WorkerTypes /** * Pool events emitter. */ -export class PoolEmitter extends EventEmitterAsyncResource {} +export class PoolEmitter extends EventEmitter {} /** * Enumeration of pool events. diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 20fac7cc..35853b7d 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -144,10 +144,6 @@ export interface WorkerInfo { * Started flag. */ started: boolean - /** - * Shared buffer. - */ - readonly sharedBuffer?: Int32Array } /** diff --git a/src/utils.ts b/src/utils.ts index f3952ab1..80e6b9f3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import os from 'node:os' +import { cpus, availableParallelism as parallelism } from 'node:os' import type { MeasurementStatisticsRequirements, WorkerChoiceStrategyOptions @@ -41,11 +41,11 @@ export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: MeasurementStatisticsR export const availableParallelism = (): number => { let availableParallelism = 1 try { - availableParallelism = os.availableParallelism() + availableParallelism = parallelism() } catch { - const cpus = os.cpus() - if (Array.isArray(cpus) && cpus.length > 0) { - availableParallelism = cpus.length + const numberOfCpus = cpus() + if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { + availableParallelism = numberOfCpus.length } } return availableParallelism diff --git a/tsconfig.json b/tsconfig.json index c2c97a36..ce2bf2c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,6 @@ "module": "ES2022", "outDir": "lib", "moduleResolution": "Node", - "esModuleInterop": true, "declaration": true, "strict": true, "forceConsistentCasingInFileNames": true -- 2.34.1