mocha: true
},
parserOptions: {
- ecmaVersion: 2022,
- sourceType: 'module'
+ sourceType: 'module',
+ ecmaVersion: 2022
},
- plugins: ['promise', 'spellcheck'],
+ plugins: ['simple-import-sort', 'promise', 'spellcheck'],
extends: [
'eslint:recommended',
'plugin:import/recommended',
}
},
rules: {
- 'sort-imports': [
- 'error',
- {
- ignoreDeclarationSort: true
- }
- ],
- 'import/order': 'error',
+ 'simple-import-sort/imports': 'error',
+ 'simple-import-sort/exports': 'error',
'spellcheck/spell-checker': [
'warn',
import { exit } from 'node:process'
+
import {
+ availableParallelism,
PoolTypes,
- WorkerTypes,
- availableParallelism
+ WorkerTypes
} from '../../lib/index.mjs'
import { TaskFunctions } from '../benchmarks-types.cjs'
import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs'
import { isMainThread } from 'node:worker_threads'
+
import { ThreadWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.cjs'
import { TaskFunctions } from '../benchmarks-types.cjs'
+import { executeTaskFunction } from '../benchmarks-utils.cjs'
const taskFunction = data => {
data = data || {}
import { randomInt } from 'node:crypto'
+
import Benchmark from 'benchmark'
+
import { LIST_FORMATTER } from '../benchmarks-utils.cjs'
function generateRandomTasksMap (
import Benchmark from 'benchmark'
+
import { LIST_FORMATTER } from '../benchmarks-utils.cjs'
function generateWorkersArray (numberOfWorkers) {
import { availableParallelism } from 'poolifier'
+
import { httpClientPool } from './pool.js'
import type { WorkerResponse } from './types.js'
-import { fileURLToPath } from 'node:url'
import { dirname, extname, join } from 'node:path'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+import { fileURLToPath } from 'node:url'
+
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
import type { URL } from 'node:url'
+
+import type { AxiosRequestConfig } from 'axios'
import {
type RequestInfo as NodeFetchRequestInfo,
type RequestInit as NodeFetchRequestInit
} from 'node-fetch'
-import type { AxiosRequestConfig } from 'axios'
export interface WorkerData {
input: URL | RequestInfo | NodeFetchRequestInfo
-import { ThreadWorker } from 'poolifier'
+import axios from 'axios'
import nodeFetch, {
type RequestInfo as NodeFetchRequestInfo,
type ResponseInit as NodeFetchRequestInit
} from 'node-fetch'
-import axios from 'axios'
+import { ThreadWorker } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
class HttpClientWorker extends ThreadWorker<WorkerData, WorkerResponse> {
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: ['./src/main.ts', './src/worker.ts'],
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
import type { Server } from 'node:http'
import type { AddressInfo } from 'node:net'
-import { ClusterWorker } from 'poolifier'
+
import express, { type Express, type Request, type Response } from 'express'
+import { ClusterWorker } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
class ExpressWorker extends ClusterWorker<WorkerData, WorkerResponse> {
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: [
import type { Server } from 'node:http'
import type { AddressInfo } from 'node:net'
+
+import express, { type Express, type Request, type Response } from 'express'
import {
+ availableParallelism,
ClusterWorker,
- DynamicThreadPool,
- availableParallelism
+ DynamicThreadPool
} from 'poolifier'
-import express, { type Express, type Request, type Response } from 'express'
+
import {
type ClusterWorkerData,
type ClusterWorkerResponse,
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
const expressWorkerFile = join(
import { ThreadWorker } from 'poolifier'
+
import {
type DataPayload,
type ThreadWorkerData,
import { exit } from 'node:process'
+
import express, { type Express, type Request, type Response } from 'express'
+
import { requestHandlerPool } from './pool.js'
/**
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import {
type BodyPayload,
type WorkerData,
import { ThreadWorker } from 'poolifier'
+
import {
type BodyPayload,
type WorkerData,
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: ['./src/main.ts', './src/worker.ts'],
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
import type { AddressInfo } from 'node:net'
-import { ClusterWorker } from 'poolifier'
+
import Fastify, { type FastifyInstance } from 'fastify'
+import { ClusterWorker } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
import type { TransferListItem } from 'node:worker_threads'
+
import type * as fastify from 'fastify'
import type { DynamicThreadPool } from 'poolifier'
+
import {
type ThreadWorkerData,
type ThreadWorkerResponse
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: [
import type { TransferListItem } from 'node:worker_threads'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+
import type { FastifyPluginCallback } from 'fastify'
import fp from 'fastify-plugin'
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import {
type FastifyPoolifierOptions,
type ThreadWorkerData,
import type { AddressInfo } from 'node:net'
-import { ClusterWorker } from 'poolifier'
+
import Fastify, { type FastifyInstance } from 'fastify'
-import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
+import { ClusterWorker } from 'poolifier'
+
import { fastifyPoolifier } from './fastify-poolifier.js'
+import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
class FastifyWorker extends ClusterWorker<
ClusterWorkerData,
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
const fastifyWorkerFile = join(
import { ThreadWorker } from 'poolifier'
+
import {
type DataPayload,
type ThreadWorkerData,
import type { TransferListItem } from 'node:worker_threads'
+
import type * as fastify from 'fastify'
import type { DynamicThreadPool } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from '../../src/types.ts'
declare module 'fastify' {
import type { TransferListItem } from 'node:worker_threads'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+
import type { FastifyPluginCallback } from 'fastify'
import fp from 'fastify-plugin'
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import {
type FastifyPoolifierOptions,
type WorkerData,
import { dirname, extname, join } from 'node:path'
-import { fileURLToPath } from 'node:url'
import { exit } from 'node:process'
+import { fileURLToPath } from 'node:url'
+
import Fastify from 'fastify'
+
import { fastifyPoolifier } from './fastify-poolifier.js'
/**
import { ThreadWorker } from 'poolifier'
+
import {
type BodyPayload,
type WorkerData,
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import type { MyData, MyResponse } from './worker.js'
+
import {
+ availableParallelism,
DynamicThreadPool,
- FixedThreadPool,
- availableParallelism
+ FixedThreadPool
} from 'poolifier'
+import type { MyData, MyResponse } from './worker.js'
+
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
`worker${extname(fileURLToPath(import.meta.url))}`
import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
+
import { smtpClientPool } from './pool.js'
const tos = ['bar@example.com, baz@example.com']
-import { fileURLToPath } from 'node:url'
import { dirname, extname, join } from 'node:path'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+import { fileURLToPath } from 'node:url'
+
import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import type { WorkerData } from './types.js'
const workerFile = join(
-import { ThreadWorker } from 'poolifier'
import { createTransport } from 'nodemailer'
import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
+import { ThreadWorker } from 'poolifier'
+
import type { WorkerData } from './types.js'
class SmtpClientWorker extends ThreadWorker<
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: ['./src/main.ts', './src/worker.ts'],
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
import { ClusterWorker } from 'poolifier'
import { type RawData, WebSocketServer } from 'ws'
+
import {
type DataPayload,
type MessagePayload,
import typescript from '@rollup/plugin-typescript'
-import del from 'rollup-plugin-delete'
import { defineConfig } from 'rollup'
+import del from 'rollup-plugin-delete'
export default defineConfig({
input: [
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { FixedClusterPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, FixedClusterPool } from 'poolifier'
+
import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
const webSocketServerWorkerFile = join(
import { ThreadWorker } from 'poolifier'
+
import {
type DataPayload,
type ThreadWorkerData,
import {
+ availableParallelism,
ClusterWorker,
- DynamicThreadPool,
- availableParallelism
+ DynamicThreadPool
} from 'poolifier'
import { type RawData, WebSocketServer } from 'ws'
+
import {
type ClusterWorkerData,
type ClusterWorkerResponse,
import { type RawData, WebSocketServer } from 'ws'
-import { type DataPayload, type MessagePayload, MessageType } from './types.js'
+
import { requestHandlerPool } from './pool.js'
+import { type DataPayload, type MessagePayload, MessageType } from './types.js'
const port = 8080
const wss = new WebSocketServer({ port }, () => {
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { DynamicThreadPool, availableParallelism } from 'poolifier'
+
+import { availableParallelism, DynamicThreadPool } from 'poolifier'
+
import {
type DataPayload,
type WorkerData,
import { ThreadWorker } from 'poolifier'
+
import {
type DataPayload,
type WorkerData,
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
+ "eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-spellcheck": "^0.0.20",
"eslint-plugin-tsdoc": "^0.2.17",
"expect": "^29.7.0",
eslint-plugin-promise:
specifier: ^6.1.1
version: 6.1.1(eslint@8.57.0)
+ eslint-plugin-simple-import-sort:
+ specifier: ^12.0.0
+ version: 12.0.0(eslint@8.57.0)
eslint-plugin-spellcheck:
specifier: ^0.0.20
version: 0.0.20(eslint@8.57.0)
eslint: 8.57.0
dev: true
+ /eslint-plugin-simple-import-sort@12.0.0(eslint@8.57.0):
+ resolution: {integrity: sha512-8o0dVEdAkYap0Cn5kNeklaKcT1nUsa3LITWEuFk3nJifOoD+5JQGoyDUW2W/iPWwBsNBJpyJS9y4je/BgxLcyQ==}
+ peerDependencies:
+ eslint: '>=5.0.0'
+ dependencies:
+ eslint: 8.57.0
+ dev: true
+
/eslint-plugin-spellcheck@0.0.20(eslint@8.57.0):
resolution: {integrity: sha512-GJa6vgzWAYqe0elKADAsiBRrhvqBnKyt7tpFSqlCZJsK2W9+K80oMyHhKolA7vJ13H5RCGs5/KCN+mKUyKoAiA==}
peerDependencies:
import * as os from 'node:os'
import { env } from 'node:process'
-import { dts } from 'rollup-plugin-dts'
+
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
+import { defineConfig } from 'rollup'
import analyze from 'rollup-plugin-analyzer'
import command from 'rollup-plugin-command'
import del from 'rollup-plugin-delete'
-import { defineConfig } from 'rollup'
+import { dts } from 'rollup-plugin-dts'
const availableParallelism = () => {
let availableParallelism = 1
+export type { CircularArray } from './circular-array.js'
+export type { Deque, ILinkedListNode } from './deque.js'
export type { AbstractPool } from './pools/abstract-pool.js'
export { DynamicClusterPool } from './pools/cluster/dynamic.js'
-export { FixedClusterPool } from './pools/cluster/fixed.js'
export type { ClusterPoolOptions } from './pools/cluster/fixed.js'
-export { PoolEvents, PoolTypes } from './pools/pool.js'
+export { FixedClusterPool } from './pools/cluster/fixed.js'
export type {
IPool,
PoolEvent,
PoolType,
TasksQueueOptions
} from './pools/pool.js'
-export { WorkerTypes } from './pools/worker.js'
+export { PoolEvents, PoolTypes } from './pools/pool.js'
+export type {
+ IWorkerChoiceStrategy,
+ Measurement,
+ MeasurementOptions,
+ MeasurementStatisticsRequirements,
+ StrategyPolicy,
+ TaskStatisticsRequirements,
+ WorkerChoiceStrategy,
+ WorkerChoiceStrategyOptions
+} from './pools/selection-strategies/selection-strategies-types.js'
+export {
+ Measurements,
+ WorkerChoiceStrategies
+} from './pools/selection-strategies/selection-strategies-types.js'
+export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context.js'
+export { DynamicThreadPool } from './pools/thread/dynamic.js'
+export type { ThreadPoolOptions } from './pools/thread/fixed.js'
+export { FixedThreadPool } from './pools/thread/fixed.js'
export type {
ErrorHandler,
EventHandler,
WorkerType,
WorkerUsage
} from './pools/worker.js'
-export {
- Measurements,
- WorkerChoiceStrategies
-} from './pools/selection-strategies/selection-strategies-types.js'
+export { WorkerTypes } from './pools/worker.js'
export type {
- IWorkerChoiceStrategy,
- Measurement,
- MeasurementOptions,
- MeasurementStatisticsRequirements,
- StrategyPolicy,
- TaskStatisticsRequirements,
- WorkerChoiceStrategy,
- WorkerChoiceStrategyOptions
-} from './pools/selection-strategies/selection-strategies-types.js'
-export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context.js'
-export { DynamicThreadPool } from './pools/thread/dynamic.js'
-export { FixedThreadPool } from './pools/thread/fixed.js'
-export type { ThreadPoolOptions } from './pools/thread/fixed.js'
+ MessageValue,
+ PromiseResponseWrapper,
+ Task,
+ TaskPerformance,
+ WorkerError,
+ WorkerStatistics,
+ Writable
+} from './utility-types.js'
+export { availableParallelism } from './utils.js'
export type { AbstractWorker } from './worker/abstract-worker.js'
export { ClusterWorker } from './worker/cluster-worker.js'
-export { ThreadWorker } from './worker/thread-worker.js'
-export { KillBehaviors } from './worker/worker-options.js'
-export type {
- KillBehavior,
- KillHandler,
- WorkerOptions
-} from './worker/worker-options.js'
export type {
TaskAsyncFunction,
TaskFunction,
TaskFunctions,
TaskSyncFunction
} from './worker/task-functions.js'
+export { ThreadWorker } from './worker/thread-worker.js'
export type {
- MessageValue,
- PromiseResponseWrapper,
- Task,
- TaskPerformance,
- WorkerError,
- WorkerStatistics,
- Writable
-} from './utility-types.js'
-export type { CircularArray } from './circular-array.js'
-export type { Deque, ILinkedListNode } from './deque.js'
-export { availableParallelism } from './utils.js'
+ KillBehavior,
+ KillHandler,
+ WorkerOptions
+} from './worker/worker-options.js'
+export { KillBehaviors } from './worker/worker-options.js'
+import { AsyncResource } from 'node:async_hooks'
import { randomUUID } from 'node:crypto'
+import { EventEmitterAsyncResource } from 'node:events'
import { performance } from 'node:perf_hooks'
import type { TransferListItem } from 'node:worker_threads'
-import { EventEmitterAsyncResource } from 'node:events'
-import { AsyncResource } from 'node:async_hooks'
+
import type {
MessageValue,
PromiseResponseWrapper,
Task
} from '../utility-types.js'
import {
+ average,
DEFAULT_TASK_NAME,
EMPTY_FUNCTION,
- average,
exponentialDelay,
isKillBehavior,
isPlainObject,
round,
sleep
} from '../utils.js'
-import { KillBehaviors } from '../worker/worker-options.js'
import type { TaskFunction } from '../worker/task-functions.js'
+import { KillBehaviors } from '../worker/worker-options.js'
import {
type IPool,
PoolEvents,
PoolTypes,
type TasksQueueOptions
} from './pool.js'
-import type {
- IWorker,
- IWorkerNode,
- WorkerInfo,
- WorkerNodeEventDetail,
- WorkerType
-} from './worker.js'
import {
Measurements,
WorkerChoiceStrategies,
type WorkerChoiceStrategyOptions
} from './selection-strategies/selection-strategies-types.js'
import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js'
-import { version } from './version.js'
-import { WorkerNode } from './worker-node.js'
import {
checkFilePath,
checkValidTasksQueueOptions,
updateWaitTimeWorkerUsage,
waitWorkerNodeEvents
} from './utils.js'
+import { version } from './version.js'
+import type {
+ IWorker,
+ IWorkerNode,
+ WorkerInfo,
+ WorkerNodeEventDetail,
+ WorkerType
+} from './worker.js'
+import { WorkerNode } from './worker-node.js'
/**
* Base class that implements some shared logic for all poolifier pools.
-import { checkDynamicPoolSize } from '../utils.js'
import { PoolEvents, type PoolType, PoolTypes } from '../pool.js'
+import { checkDynamicPoolSize } from '../utils.js'
import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js'
/**
import cluster, { type Worker } from 'node:cluster'
+
import type { MessageValue } from '../../utility-types.js'
import { AbstractPool } from '../abstract-pool.js'
import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js'
-import type { TransferListItem, WorkerOptions } from 'node:worker_threads'
-import type { EventEmitterAsyncResource } from 'node:events'
import type { ClusterSettings } from 'node:cluster'
+import type { EventEmitterAsyncResource } from 'node:events'
+import type { TransferListItem, WorkerOptions } from 'node:worker_threads'
+
import type { TaskFunction } from '../worker/task-functions.js'
+import type {
+ WorkerChoiceStrategy,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies/selection-strategies-types.js'
import type {
ErrorHandler,
ExitHandler,
OnlineHandler,
WorkerType
} from './worker.js'
-import type {
- WorkerChoiceStrategy,
- WorkerChoiceStrategyOptions
-} from './selection-strategies/selection-strategies-types.js'
/**
* Enumeration of pool types.
import type { IPool } from '../pool.js'
import {
- DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
- buildWorkerChoiceStrategyOptions
+ buildWorkerChoiceStrategyOptions,
+ DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS
} from '../utils.js'
import type { IWorker } from '../worker.js'
import type {
-import type { IWorker } from '../worker.js'
import type { IPool } from '../pool.js'
import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js'
+import type { IWorker } from '../worker.js'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
-import type { IWorker } from '../worker.js'
import type { IPool } from '../pool.js'
import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js'
+import type { IWorker } from '../worker.js'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
import type { IPool } from '../pool.js'
-import type { IWorker } from '../worker.js'
import { getWorkerChoiceStrategyRetries } from '../utils.js'
+import type { IWorker } from '../worker.js'
import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy.js'
import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy.js'
import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy.js'
-import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js'
import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy.js'
+import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js'
import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
import {
+ isMainThread,
type TransferListItem,
- type Worker,
- isMainThread
+ type Worker
} from 'node:worker_threads'
+
import type { MessageValue } from '../../utility-types.js'
import { AbstractPool } from '../abstract-pool.js'
import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js'
-import { existsSync } from 'node:fs'
import cluster, { Worker as ClusterWorker } from 'node:cluster'
+import { randomInt } from 'node:crypto'
+import { existsSync } from 'node:fs'
+import { cpus } from 'node:os'
+import { env } from 'node:process'
import {
SHARE_ENV,
Worker as ThreadWorker,
type WorkerOptions
} from 'node:worker_threads'
-import { env } from 'node:process'
-import { randomInt } from 'node:crypto'
-import { cpus } from 'node:os'
-import { average, isPlainObject, max, median, min } from '../utils.js'
+
import type { MessageValue, Task } from '../utility-types.js'
+import { average, isPlainObject, max, median, min } from '../utils.js'
+import type { IPool, TasksQueueOptions } from './pool.js'
import {
type MeasurementStatisticsRequirements,
WorkerChoiceStrategies,
type WorkerChoiceStrategy,
type WorkerChoiceStrategyOptions
} from './selection-strategies/selection-strategies-types.js'
-import type { IPool, TasksQueueOptions } from './pool.js'
+import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js'
import {
type IWorker,
type IWorkerNode,
WorkerTypes,
type WorkerUsage
} from './worker.js'
-import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js'
/**
* Default measurement statistics requirements.
-import { MessageChannel } from 'node:worker_threads'
import { EventEmitter } from 'node:events'
+import { MessageChannel } from 'node:worker_threads'
+
import { CircularArray } from '../circular-array.js'
+import { Deque } from '../deque.js'
import type { Task } from '../utility-types.js'
import { DEFAULT_TASK_NAME } from '../utils.js'
-import { Deque } from '../deque.js'
+import {
+ checkWorkerNodeArguments,
+ createWorker,
+ getWorkerId,
+ getWorkerType
+} from './utils.js'
import {
type EventHandler,
type IWorker,
WorkerTypes,
type WorkerUsage
} from './worker.js'
-import {
- checkWorkerNodeArguments,
- createWorker,
- getWorkerId,
- getWorkerType
-} from './utils.js'
/**
* Worker node.
-import type { MessageChannel, WorkerOptions } from 'node:worker_threads'
import type { EventEmitter } from 'node:events'
+import type { MessageChannel, WorkerOptions } from 'node:worker_threads'
+
import type { CircularArray } from '../circular-array.js'
import type { Task } from '../utility-types.js'
+import type { AsyncResource } from 'node:async_hooks'
import type { EventLoopUtilization } from 'node:perf_hooks'
import type { MessagePort, TransferListItem } from 'node:worker_threads'
-import type { AsyncResource } from 'node:async_hooks'
+
import type { KillBehavior } from './worker/worker-options.js'
/**
-import * as os from 'node:os'
import { getRandomValues } from 'node:crypto'
+import * as os from 'node:os'
+
import type { KillBehavior } from './worker/worker-options.js'
/**
import type { Worker } from 'node:cluster'
-import type { MessagePort } from 'node:worker_threads'
import { performance } from 'node:perf_hooks'
+import type { MessagePort } from 'node:worker_threads'
+
import type {
MessageValue,
Task,
isAsyncFunction,
isPlainObject
} from '../utils.js'
-import { KillBehaviors, type WorkerOptions } from './worker-options.js'
import type {
TaskAsyncFunction,
TaskFunction,
checkValidTaskFunctionEntry,
checkValidWorkerOptions
} from './utils.js'
+import { KillBehaviors, type WorkerOptions } from './worker-options.js'
const DEFAULT_MAX_INACTIVE_TIME = 60000
const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
import cluster, { type Worker } from 'node:cluster'
+
import type { MessageValue } from '../utility-types.js'
import { AbstractWorker } from './abstract-worker.js'
-import type { WorkerOptions } from './worker-options.js'
import type { TaskFunction, TaskFunctions } from './task-functions.js'
+import type { WorkerOptions } from './worker-options.js'
/**
* A cluster worker used by a poolifier `ClusterPool`.
import {
- type MessagePort,
isMainThread,
+ type MessagePort,
parentPort,
threadId
} from 'node:worker_threads'
+
import type { MessageValue } from '../utility-types.js'
import { AbstractWorker } from './abstract-worker.js'
-import type { WorkerOptions } from './worker-options.js'
import type { TaskFunction, TaskFunctions } from './task-functions.js'
+import type { WorkerOptions } from './worker-options.js'
/**
* A thread worker used by a poolifier `ThreadPool`.
import { expect } from 'expect'
+
import {
CircularArray,
DEFAULT_CIRCULAR_ARRAY_SIZE
import { expect } from 'expect'
+
import { Deque } from '../lib/deque.cjs'
describe('Deque test suite', () => {
+import { createHook, executionAsyncId } from 'node:async_hooks'
import { EventEmitterAsyncResource } from 'node:events'
-import { dirname, join } from 'node:path'
import { readFileSync } from 'node:fs'
+import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { createHook, executionAsyncId } from 'node:async_hooks'
+
import { expect } from 'expect'
import { restore, stub } from 'sinon'
+
+import { CircularArray } from '../../lib/circular-array.cjs'
+import { Deque } from '../../lib/deque.cjs'
import {
DynamicClusterPool,
DynamicThreadPool,
WorkerChoiceStrategies,
WorkerTypes
} from '../../lib/index.cjs'
-import { CircularArray } from '../../lib/circular-array.cjs'
-import { Deque } from '../../lib/deque.cjs'
+import { WorkerNode } from '../../lib/pools/worker-node.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
import { waitPoolEvents } from '../test-utils.cjs'
-import { WorkerNode } from '../../lib/pools/worker-node.cjs'
describe('Abstract pool test suite', () => {
const version = JSON.parse(
import { expect } from 'expect'
+
import {
DynamicClusterPool,
PoolEvents,
import { expect } from 'expect'
+
import { FixedClusterPool, PoolEvents } from '../../../lib/index.cjs'
+import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs'
import { TaskFunctions } from '../../test-types.cjs'
import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs'
-import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs'
describe('Fixed cluster pool test suite', () => {
const numberOfWorkers = 8
import { expect } from 'expect'
+
+import { CircularArray } from '../../../lib/circular-array.cjs'
import {
DynamicClusterPool,
DynamicThreadPool,
FixedThreadPool,
WorkerChoiceStrategies
} from '../../../lib/index.cjs'
-import { CircularArray } from '../../../lib/circular-array.cjs'
describe('Selection strategies test suite', () => {
const min = 0
import { randomInt } from 'node:crypto'
+
import { expect } from 'expect'
+
import { FixedThreadPool } from '../../../lib/index.cjs'
import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs'
import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
import { expect } from 'expect'
import { createStubInstance, restore, stub } from 'sinon'
+
import {
DynamicThreadPool,
FixedThreadPool,
WorkerChoiceStrategies
} from '../../../lib/index.cjs'
-import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.cjs'
-import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.cjs'
-import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.cjs'
+import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.cjs'
+import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs'
import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.cjs'
import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.cjs'
-import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.cjs'
+import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.cjs'
+import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.cjs'
import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
-import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs'
+import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.cjs'
describe('Worker choice strategy context test suite', () => {
const min = 1
import { expect } from 'expect'
+
import {
DynamicThreadPool,
PoolEvents,
import { expect } from 'expect'
+
import { FixedThreadPool, PoolEvents } from '../../../lib/index.cjs'
+import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs'
import { TaskFunctions } from '../../test-types.cjs'
import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs'
-import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs'
describe('Fixed thread pool test suite', () => {
const numberOfThreads = 6
-import { Worker as ThreadWorker } from 'node:worker_threads'
import cluster, { Worker as ClusterWorker } from 'node:cluster'
+import { Worker as ThreadWorker } from 'node:worker_threads'
+
import { expect } from 'expect'
+
import {
CircularArray,
DEFAULT_CIRCULAR_ARRAY_SIZE
} from '../../lib/circular-array.cjs'
import {
- DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
+ FixedClusterPool,
+ FixedThreadPool,
+ WorkerTypes
+} from '../../lib/index.cjs'
+import {
buildWorkerChoiceStrategyOptions,
createWorker,
+ DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
getDefaultTasksQueueOptions,
getWorkerChoiceStrategyRetries,
getWorkerId,
getWorkerType,
updateMeasurementStatistics
} from '../../lib/pools/utils.cjs'
-import {
- FixedClusterPool,
- FixedThreadPool,
- WorkerTypes
-} from '../../lib/index.cjs'
describe('Pool utils test suite', () => {
it('Verify DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS values', () => {
-import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads'
import { Worker as ClusterWorker } from 'node:cluster'
+import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads'
+
import { expect } from 'expect'
-import { WorkerNode } from '../../lib/pools/worker-node.cjs'
-import { WorkerTypes } from '../../lib/index.cjs'
+
import { CircularArray } from '../../lib/circular-array.cjs'
import { Deque } from '../../lib/deque.cjs'
+import { WorkerTypes } from '../../lib/index.cjs'
+import { WorkerNode } from '../../lib/pools/worker-node.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
describe('Worker node test suite', () => {
-import os from 'node:os'
import { randomInt } from 'node:crypto'
+import os from 'node:os'
+
import { expect } from 'expect'
+
+import { KillBehaviors } from '../lib/index.cjs'
import {
- DEFAULT_TASK_NAME,
- EMPTY_FUNCTION,
availableParallelism,
average,
+ DEFAULT_TASK_NAME,
+ EMPTY_FUNCTION,
exponentialDelay,
isAsyncFunction,
isKillBehavior,
secureRandom,
sleep
} from '../lib/utils.cjs'
-import { KillBehaviors } from '../lib/index.cjs'
describe('Utils test suite', () => {
it('Verify DEFAULT_TASK_NAME value', () => {
import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
-import { executeTaskFunction } from '../../test-utils.cjs'
import { TaskFunctions } from '../../test-types.cjs'
+import { executeTaskFunction } from '../../test-utils.cjs'
/**
*
import { expect } from 'expect'
import { restore, stub } from 'sinon'
+
import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.cjs'
import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.cjs'
import { expect } from 'expect'
import { restore, stub } from 'sinon'
+
import { ClusterWorker } from '../../lib/index.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
import { expect } from 'expect'
import { restore, stub } from 'sinon'
+
import { ThreadWorker } from '../../lib/index.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
+import { execSync } from 'node:child_process'
import { copyFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import { execSync } from 'node:child_process'
try {
mkdirSync(join(dirname(fileURLToPath(import.meta.url)), 'tmp'), {