}
},
{
- files: ['**/*.js', '**/*.mjs'],
+ files: ['**/*.cjs', '**/*.mjs'],
plugins: ['jsdoc'],
extends: ['plugin:n/recommended', 'plugin:jsdoc/recommended', 'standard']
},
{
- files: ['tests/**/*.js', 'tests/**/*.mjs'],
+ files: ['tests/**/*.cjs', 'tests/**/*.mjs'],
rules: {
'jsdoc/require-jsdoc': 'off'
}
},
{
- files: ['benchmarks/**/*.js', 'benchmarks/**/*.mjs'],
+ files: ['benchmarks/**/*.cjs', 'benchmarks/**/*.mjs'],
rules: {
'jsdoc/require-jsdoc': 'off'
}
},
{
- files: ['examples/javascript/**/*.js'],
+ files: ['examples/javascript/**/*.cjs'],
rules: {
'jsdoc/require-jsdoc': 'off'
}
-module.exports = {
+export default {
'**/*.{ts,tsx,js,jsx,cjs,mjs}': [
'biome format --write',
'ts-standard --fix',
You can implement a [worker_threads](https://nodejs.org/api/worker_threads.html#class-worker) worker in a simple way by extending the class _ThreadWorker_:
```js
-'use strict'
-const { ThreadWorker } = require('poolifier')
+import { ThreadWorker } from 'poolifier'
function yourFunction(data) {
// this will be executed in the worker thread,
Instantiate your pool based on your needs :
```js
-'use strict'
-const { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } = require('poolifier')
+import { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } from 'poolifier'
// a fixed worker_threads pool
const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {
PoolTypes,
WorkerChoiceStrategies,
WorkerTypes
-} = require('../lib/index.js')
-const { TaskFunctions } = require('./benchmarks-types.js')
+} = require('../lib/index.cjs')
+const { TaskFunctions } = require('./benchmarks-types.cjs')
const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => {
switch (poolType) {
case WorkerTypes.cluster:
return new FixedClusterPool(
poolSize,
- './benchmarks/internal/cluster-worker.js',
+ './benchmarks/internal/cluster-worker.cjs',
poolOptions
)
}
return new DynamicClusterPool(
Math.floor(poolSize / 2),
poolSize,
- './benchmarks/internal/cluster-worker.js',
+ './benchmarks/internal/cluster-worker.cjs',
poolOptions
)
}
WorkerTypes,
availableParallelism
} from '../../lib/index.mjs'
-import { TaskFunctions } from '../benchmarks-types.js'
-import { runPoolifierPoolBenchmark } from '../benchmarks-utils.js'
+import { TaskFunctions } from '../benchmarks-types.cjs'
+import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs'
const poolSize = availableParallelism()
const taskExecutions = 1
const { isPrimary } = require('node:cluster')
-const { ClusterWorker } = require('../../lib')
-const { executeTaskFunction } = require('../benchmarks-utils.js')
-const { TaskFunctions } = require('../benchmarks-types.js')
+const { ClusterWorker } = require('../../lib/index.cjs')
+const { executeTaskFunction } = require('../benchmarks-utils.cjs')
+const { TaskFunctions } = require('../benchmarks-types.cjs')
const taskFunction = data => {
data = data || {}
import { isMainThread } from 'node:worker_threads'
import { ThreadWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.js'
-import { TaskFunctions } from '../benchmarks-types.js'
+import { executeTaskFunction } from '../benchmarks-utils.cjs'
+import { TaskFunctions } from '../benchmarks-types.cjs'
const taskFunction = data => {
data = data || {}
import Benchmark from 'benchmark'
-import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.js'
+import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.cjs'
function generateRandomTasksMap (
numberOfWorkers,
import Benchmark from 'benchmark'
-import { LIST_FORMATTER } from '../benchmarks-utils.js'
+import { LIST_FORMATTER } from '../benchmarks-utils.cjs'
function generateWorkersArray (numberOfWorkers) {
return [...Array(numberOfWorkers).keys()]
-module.exports = { extends: ['@commitlint/config-conventional'] }
+export default { extends: ['@commitlint/config-conventional'] }
availableParallelism
} = require('poolifier')
-const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {
+const pool = new FixedThreadPool(availableParallelism(), './yourWorker.cjs', {
errorHandler: e => console.error(e),
onlineHandler: () => console.info('worker is online')
})
const pool = new FixedThreadPool(
availableParallelism(),
- './multiFunctionWorker.js',
+ './multiFunctionWorker.cjs',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.info('worker is online')
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import type { MyData, MyResponse } from './worker'
+import type { MyData, MyResponse } from './worker.js'
import {
DynamicThreadPool,
FixedThreadPool,
"version": "3.1.11",
"description": "Fast and small Node.js Worker_Threads and Cluster Worker Pool",
"license": "MIT",
- "main": "./lib/index.js",
+ "type": "module",
+ "main": "./lib/index.cjs",
"exports": {
".": {
"types": "./lib/index.d.ts",
- "require": "./lib/index.js",
+ "require": "./lib/index.cjs",
"import": "./lib/index.mjs"
}
},
format: 'cjs',
...(isDevelopmentBuild && {
dir: './lib',
+ entryFileNames: '[name].cjs',
+ chunkFileNames: '[name]-[hash].cjs',
preserveModules: true,
preserveModulesRoot: './src'
}),
...(!isDevelopmentBuild && {
- file: './lib/index.js',
+ file: './lib/index.cjs',
plugins: [terser({ maxWorkers })]
}),
...(sourcemap && {
-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 { 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 type {
IPool,
PoolEvent,
PoolOptions,
PoolType,
TasksQueueOptions
-} from './pools/pool'
-export { WorkerTypes } from './pools/worker'
+} from './pools/pool.js'
+export { WorkerTypes } from './pools/worker.js'
export type {
ErrorHandler,
EventLoopUtilizationMeasurementStatistics,
WorkerNodeOptions,
WorkerType,
WorkerUsage
-} from './pools/worker'
+} from './pools/worker.js'
export {
Measurements,
WorkerChoiceStrategies
-} from './pools/selection-strategies/selection-strategies-types'
+} from './pools/selection-strategies/selection-strategies-types.js'
export type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
TaskStatisticsRequirements,
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
-} from './pools/selection-strategies/selection-strategies-types'
-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'
-export { KillBehaviors } from './worker/worker-options'
+} 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'
+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'
+} from './worker/worker-options.js'
export type {
TaskAsyncFunction,
TaskFunction,
TaskFunctionOperationResult,
TaskFunctions,
TaskSyncFunction
-} from './worker/task-functions'
+} from './worker/task-functions.js'
export type {
MessageValue,
PromiseResponseWrapper,
WorkerError,
WorkerStatistics,
Writable
-} from './utility-types'
-export type { CircularArray } from './circular-array'
-export type { Deque, Node } from './deque'
-export { availableParallelism } from './utils'
+} from './utility-types.js'
+export type { CircularArray } from './circular-array.js'
+export type { Deque, Node } from './deque.js'
+export { availableParallelism } from './utils.js'
MessageValue,
PromiseResponseWrapper,
Task
-} from '../utility-types'
+} from '../utility-types.js'
import {
DEFAULT_TASK_NAME,
EMPTY_FUNCTION,
min,
round,
sleep
-} from '../utils'
-import { KillBehaviors } from '../worker/worker-options'
-import type { TaskFunction } from '../worker/task-functions'
+} from '../utils.js'
+import { KillBehaviors } from '../worker/worker-options.js'
+import type { TaskFunction } from '../worker/task-functions.js'
import {
type IPool,
PoolEvents,
type PoolType,
PoolTypes,
type TasksQueueOptions
-} from './pool'
+} from './pool.js'
import type {
IWorker,
IWorkerNode,
WorkerNodeEventDetail,
WorkerType,
WorkerUsage
-} from './worker'
+} from './worker.js'
import {
Measurements,
WorkerChoiceStrategies,
type WorkerChoiceStrategy,
type WorkerChoiceStrategyOptions
-} from './selection-strategies/selection-strategies-types'
-import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
-import { version } from './version'
-import { WorkerNode } from './worker-node'
+} 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,
updateTaskStatisticsWorkerUsage,
updateWaitTimeWorkerUsage,
waitWorkerNodeEvents
-} from './utils'
+} from './utils.js'
/**
* Base class that implements some shared logic for all poolifier pools.
-import { checkDynamicPoolSize } from '../utils'
-import { PoolEvents, type PoolType, PoolTypes } from '../pool'
-import { type ClusterPoolOptions, FixedClusterPool } from './fixed'
+import { checkDynamicPoolSize } from '../utils.js'
+import { PoolEvents, type PoolType, PoolTypes } from '../pool.js'
+import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js'
/**
* A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
import cluster, { type Worker } from 'node:cluster'
-import type { MessageValue } from '../../utility-types'
-import { AbstractPool } from '../abstract-pool'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
-import { type WorkerType, WorkerTypes } from '../worker'
+import type { MessageValue } from '../../utility-types.js'
+import { AbstractPool } from '../abstract-pool.js'
+import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js'
+import { type WorkerType, WorkerTypes } from '../worker.js'
/**
* Options for a poolifier cluster pool.
import type { TransferListItem, WorkerOptions } from 'node:worker_threads'
import type { EventEmitterAsyncResource } from 'node:events'
import type { ClusterSettings } from 'node:cluster'
-import type { TaskFunction } from '../worker/task-functions'
+import type { TaskFunction } from '../worker/task-functions.js'
import type {
ErrorHandler,
ExitHandler,
MessageHandler,
OnlineHandler,
WorkerType
-} from './worker'
+} from './worker.js'
import type {
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
-} from './selection-strategies/selection-strategies-types'
+} from './selection-strategies/selection-strategies-types.js'
/**
* Enumeration of pool types.
import {
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
buildInternalWorkerChoiceStrategyOptions
-} from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
+} from '../../utils.js'
+import type { IPool } from '../pool.js'
+import type { IWorker } from '../worker.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
MeasurementStatisticsRequirements,
StrategyPolicy,
TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Worker choice strategy abstract base class.
-import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker, StrategyData } from '../worker'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
+import type { IPool } from '../pool.js'
+import type { IWorker, StrategyData } from '../worker.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import {
type IWorkerChoiceStrategy,
type InternalWorkerChoiceStrategyOptions,
Measurements,
type TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the next worker with a fair share scheduling algorithm.
-import type { IWorker } from '../worker'
-import type { IPool } from '../pool'
-import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IWorker } from '../worker.js'
+import type { IPool } from '../pool.js'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the next worker with an interleaved weighted round robin scheduling algorithm.
-import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
+import type { IPool } from '../pool.js'
+import type { IWorker } from '../worker.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the least busy worker.
-import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
+import type { IPool } from '../pool.js'
+import type { IWorker } from '../worker.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the worker with the least ELU.
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IPool } from '../pool.js'
+import type { IWorker } from '../worker.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the least used worker.
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IPool } from '../pool.js'
+import type { IWorker } from '../worker.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the next worker in a round robin fashion.
-import type { IWorker } from '../worker'
-import type { IPool } from '../pool'
-import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
-import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
+import type { IWorker } from '../worker.js'
+import type { IPool } from '../pool.js'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
+import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
TaskStatisticsRequirements
-} from './selection-strategies-types'
+} from './selection-strategies-types.js'
/**
* Selects the next worker with a weighted round robin scheduling algorithm.
-import { buildInternalWorkerChoiceStrategyOptions } from '../../utils'
-import type { IPool } from '../pool'
-import type { IWorker } from '../worker'
-import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy'
-import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy'
-import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy'
-import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy'
-import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy'
-import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy'
+import { buildInternalWorkerChoiceStrategyOptions } from '../../utils.js'
+import type { IPool } from '../pool.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 { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy.js'
import type {
IWorkerChoiceStrategy,
InternalWorkerChoiceStrategyOptions,
StrategyPolicy,
TaskStatisticsRequirements,
WorkerChoiceStrategy
-} from './selection-strategies-types'
-import { WorkerChoiceStrategies } from './selection-strategies-types'
-import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-worker-choice-strategy'
+} from './selection-strategies-types.js'
+import { WorkerChoiceStrategies } from './selection-strategies-types.js'
+import { WeightedRoundRobinWorkerChoiceStrategy } from './weighted-round-robin-worker-choice-strategy.js'
/**
* The worker choice strategy context.
-import { PoolEvents, type PoolType, PoolTypes } from '../pool'
-import { checkDynamicPoolSize } from '../utils'
-import { FixedThreadPool, type ThreadPoolOptions } from './fixed'
+import { PoolEvents, type PoolType, PoolTypes } from '../pool.js'
+import { checkDynamicPoolSize } from '../utils.js'
+import { FixedThreadPool, type ThreadPoolOptions } from './fixed.js'
/**
* A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
type Worker,
isMainThread
} from 'node:worker_threads'
-import type { MessageValue } from '../../utility-types'
-import { AbstractPool } from '../abstract-pool'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
-import { type WorkerType, WorkerTypes } from '../worker'
+import type { MessageValue } from '../../utility-types.js'
+import { AbstractPool } from '../abstract-pool.js'
+import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js'
+import { type WorkerType, WorkerTypes } from '../worker.js'
/**
* Options for a poolifier thread pool.
import cluster from 'node:cluster'
import { SHARE_ENV, Worker, type WorkerOptions } from 'node:worker_threads'
import { env } from 'node:process'
-import { average, isPlainObject, max, median, min } from '../utils'
-import type { MessageValue, Task } from '../utility-types'
+import { average, isPlainObject, max, median, min } from '../utils.js'
+import type { MessageValue, Task } from '../utility-types.js'
import {
type MeasurementStatisticsRequirements,
WorkerChoiceStrategies,
type WorkerChoiceStrategy
-} from './selection-strategies/selection-strategies-types'
-import type { TasksQueueOptions } from './pool'
+} from './selection-strategies/selection-strategies-types.js'
+import type { TasksQueueOptions } from './pool.js'
import {
type IWorker,
type IWorkerNode,
type WorkerType,
WorkerTypes,
type WorkerUsage
-} from './worker'
-import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
+} from './worker.js'
+import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js'
export const getDefaultTasksQueueOptions = (
poolMaxSize: number
import { MessageChannel } from 'node:worker_threads'
import { EventEmitter } from 'node:events'
-import { CircularArray } from '../circular-array'
-import type { Task } from '../utility-types'
-import { DEFAULT_TASK_NAME, getWorkerId, getWorkerType } from '../utils'
-import { Deque } from '../deque'
+import { CircularArray } from '../circular-array.js'
+import type { Task } from '../utility-types.js'
+import { DEFAULT_TASK_NAME, getWorkerId, getWorkerType } from '../utils.js'
+import { Deque } from '../deque.js'
import {
type ErrorHandler,
type ExitHandler,
type WorkerType,
WorkerTypes,
type WorkerUsage
-} from './worker'
-import { checkWorkerNodeArguments, createWorker } from './utils'
+} from './worker.js'
+import { checkWorkerNodeArguments, createWorker } from './utils.js'
/**
* Worker node.
import type { MessageChannel, WorkerOptions } from 'node:worker_threads'
import type { EventEmitter } from 'node:events'
-import type { CircularArray } from '../circular-array'
-import type { Task } from '../utility-types'
+import type { CircularArray } from '../circular-array.js'
+import type { Task } from '../utility-types.js'
/**
* Callback invoked when the worker has started successfully.
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'
+import type { KillBehavior } from './worker/worker-options.js'
/**
* Worker error.
import type {
InternalWorkerChoiceStrategyOptions,
MeasurementStatisticsRequirements
-} from './pools/selection-strategies/selection-strategies-types'
-import type { KillBehavior } from './worker/worker-options'
-import { type IWorker, type WorkerType, WorkerTypes } from './pools/worker'
+} from './pools/selection-strategies/selection-strategies-types.js'
+import type { KillBehavior } from './worker/worker-options.js'
+import { type IWorker, type WorkerType, WorkerTypes } from './pools/worker.js'
/**
* Default task name.
Task,
TaskPerformance,
WorkerStatistics
-} from '../utility-types'
+} from '../utility-types.js'
import {
DEFAULT_TASK_NAME,
EMPTY_FUNCTION,
isAsyncFunction,
isPlainObject
-} from '../utils'
-import { KillBehaviors, type WorkerOptions } from './worker-options'
+} from '../utils.js'
+import { KillBehaviors, type WorkerOptions } from './worker-options.js'
import type {
TaskAsyncFunction,
TaskFunction,
TaskFunctionOperationResult,
TaskFunctions,
TaskSyncFunction
-} from './task-functions'
+} from './task-functions.js'
import {
checkTaskFunctionName,
checkValidTaskFunctionEntry,
checkValidWorkerOptions
-} from './utils'
+} from './utils.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'
-import { AbstractWorker } from './abstract-worker'
-import type { WorkerOptions } from './worker-options'
-import type { TaskFunction, TaskFunctions } from './task-functions'
+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'
/**
* A cluster worker used by a poolifier `ClusterPool`.
parentPort,
threadId
} from 'node:worker_threads'
-import type { MessageValue } from '../utility-types'
-import { AbstractWorker } from './abstract-worker'
-import type { WorkerOptions } from './worker-options'
-import type { TaskFunction, TaskFunctions } from './task-functions'
+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'
/**
* A thread worker used by a poolifier `ThreadPool`.
-import { isPlainObject } from '../utils'
-import type { TaskFunction } from './task-functions'
-import { KillBehaviors, type WorkerOptions } from './worker-options'
+import { isPlainObject } from '../utils.js'
+import type { TaskFunction } from './task-functions.js'
+import { KillBehaviors, type WorkerOptions } from './worker-options.js'
export const checkValidWorkerOptions = (opts: WorkerOptions): void => {
if (opts != null && !isPlainObject(opts)) {
import {
CircularArray,
DEFAULT_CIRCULAR_ARRAY_SIZE
-} from '../lib/circular-array.js'
+} from '../lib/circular-array.cjs'
describe('Circular array test suite', () => {
it('Verify that circular array can be instantiated', () => {
import { expect } from 'expect'
-import { Deque } from '../lib/deque.js'
+import { Deque } from '../lib/deque.cjs'
describe('Deque test suite', () => {
it('Verify push() behavior', () => {
PoolTypes,
WorkerChoiceStrategies,
WorkerTypes
-} from '../../lib/index.js'
-import { CircularArray } from '../../lib/circular-array.js'
-import { Deque } from '../../lib/deque.js'
-import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
-import { waitPoolEvents } from '../test-utils.js'
-import { WorkerNode } from '../../lib/pools/worker-node.js'
+} from '../../lib/index.cjs'
+import { CircularArray } from '../../lib/circular-array.cjs'
+import { Deque } from '../../lib/deque.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(
it('Verify that a negative number of workers is checked', () => {
expect(
() =>
- new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js')
+ new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.cjs')
).toThrow(
new RangeError(
'Cannot instantiate a pool with a negative number of workers'
new DynamicClusterPool(
1,
undefined,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
).toThrow(
new TypeError(
new DynamicClusterPool(
0,
0.5,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
).toThrow(
new TypeError(
new DynamicClusterPool(
1,
1,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
).toThrow(
new RangeError(
pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
expect(pool.info).toStrictEqual({
version,
it('Verify that pool worker tasks usage are initialized', async () => {
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
it('Verify that pool worker tasks queue are initialized', async () => {
let pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
it('Verify that pool worker info are initialized', async () => {
let pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
it('Verify that pool can be started after initialization', async () => {
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{
startWorkers: false
}
it('Verify that pool execute() arguments are checked', async () => {
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
await expect(pool.execute(undefined, 0)).rejects.toThrow(
new TypeError('name argument must be a string')
it('Verify that pool worker tasks usage are computed', async () => {
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
const promises = new Set()
const maxMultiplier = 2
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
expect(pool.emitter.eventNames()).toStrictEqual([])
let poolInfo
await dynamicThreadPool.destroy()
const fixedClusterPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs'
)
await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1)
expect(fixedClusterPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
await dynamicThreadPool.destroy()
const fixedClusterPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs'
)
await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1)
expect(fixedClusterPool.listTaskFunctionNames()).toStrictEqual([
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.cjs'
)
const data = { n: 10 }
const result0 = await pool.execute(data)
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
const workerNodeKey = 0
await expect(
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
const workerNodeKey = 0
await expect(
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
await expect(
pool.sendTaskFunctionOperationToWorkers({
import { expect } from 'expect'
-import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js'
-import { TaskFunctions } from '../../test-types.js'
-import { sleep, waitWorkerEvents } from '../../test-utils.js'
+import { DynamicClusterPool, PoolEvents } from '../../../lib/index.cjs'
+import { TaskFunctions } from '../../test-types.cjs'
+import { sleep, waitWorkerEvents } from '../../test-utils.cjs'
describe('Dynamic cluster pool test suite', () => {
const min = 1
const pool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{
errorHandler: e => console.error(e)
}
const pool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
const result = await pool.execute()
expect(result).toStrictEqual({ ok: 1 })
const longRunningPool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/longRunningWorkerHardBehavior.js',
+ './tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.info('long executing worker is online'),
const longRunningPool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js',
+ './tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.info('long executing worker is online'),
const pool = new DynamicClusterPool(
0,
max,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
expect(pool).toBeInstanceOf(DynamicClusterPool)
// We need to clean up the resources after our test
import { expect } from 'expect'
-import { FixedClusterPool, PoolEvents } from '../../../lib/index.js'
-import { TaskFunctions } from '../../test-types.js'
-import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js'
-import { DEFAULT_TASK_NAME } from '../../../lib/utils.js'
+import { FixedClusterPool, PoolEvents } from '../../../lib/index.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
const tasksConcurrency = 2
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{
errorHandler: e => console.error(e)
}
)
const queuePool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{
enableTasksQueue: true,
tasksQueueOptions: {
)
const emptyPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/emptyWorker.js',
+ './tests/worker-files/cluster/emptyWorker.cjs',
{ exitHandler: () => console.info('empty pool worker exited') }
)
const echoPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/echoWorker.js'
+ './tests/worker-files/cluster/echoWorker.cjs'
)
const errorPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/errorWorker.js',
+ './tests/worker-files/cluster/errorWorker.cjs',
{
errorHandler: e => console.error(e)
}
)
const asyncErrorPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/asyncErrorWorker.js',
+ './tests/worker-files/cluster/asyncErrorWorker.cjs',
{
errorHandler: e => console.error(e)
}
)
const asyncPool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/asyncWorker.js'
+ './tests/worker-files/cluster/asyncWorker.cjs'
)
after('Destroy all pools', async () => {
it("Verify that 'ready' event is emitted", async () => {
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{
errorHandler: e => console.error(e)
}
})
it('Verify that cluster pool options are checked', async () => {
- const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+ const workerFilePath = './tests/worker-files/cluster/testWorker.cjs'
let pool = new FixedClusterPool(numberOfWorkers, workerFilePath)
expect(pool.opts.env).toBeUndefined()
expect(pool.opts.settings).toBeUndefined()
})
it('Should work even without opts in input', async () => {
- const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+ const workerFilePath = './tests/worker-files/cluster/testWorker.cjs'
const pool = new FixedClusterPool(numberOfWorkers, workerFilePath)
const res = await pool.execute()
expect(res).toStrictEqual({ ok: 1 })
})
it('Verify destroyWorkerNode()', async () => {
- const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+ const workerFilePath = './tests/worker-files/cluster/testWorker.cjs'
const pool = new FixedClusterPool(numberOfWorkers, workerFilePath)
const workerNodeKey = 0
let disconnectEvent = 0
it('Verify that a pool with zero worker fails', () => {
expect(
() =>
- new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js')
+ new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.cjs')
).toThrow('Cannot instantiate a fixed pool with zero worker')
})
})
FixedClusterPool,
FixedThreadPool,
WorkerChoiceStrategies
-} from '../../../lib/index.js'
-import { CircularArray } from '../../../lib/circular-array.js'
+} from '../../../lib/index.cjs'
+import { CircularArray } from '../../../lib/circular-array.cjs'
describe('Selection strategies test suite', () => {
const min = 0
const pool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedClusterPool(
max,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{ workerChoiceStrategy }
)
let results = new Set()
import { expect } from 'expect'
-import { FixedThreadPool } from '../../../lib/index.js'
-import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
-import { generateRandomInteger } from '../../test-utils.js'
+import { FixedThreadPool } from '../../../lib/index.cjs'
+import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
+import { generateRandomInteger } from '../../test-utils.cjs'
describe('Weighted round robin strategy worker choice strategy test suite', () => {
// const min = 1
DynamicThreadPool,
FixedThreadPool,
WorkerChoiceStrategies
-} from '../../../lib/index.js'
-import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.js'
-import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.js'
-import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.js'
-import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.js'
-import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.js'
-import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.js'
-import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
-import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.js'
+} 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 { 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 { 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'
describe('Worker choice strategy context test suite', () => {
const min = 1
import { expect } from 'expect'
-import { DynamicThreadPool, PoolEvents } from '../../../lib/index.js'
-import { TaskFunctions } from '../../test-types.js'
-import { sleep, waitWorkerEvents } from '../../test-utils.js'
+import { DynamicThreadPool, PoolEvents } from '../../../lib/index.cjs'
+import { TaskFunctions } from '../../test-types.cjs'
+import { sleep, waitWorkerEvents } from '../../test-utils.cjs'
describe('Dynamic thread pool test suite', () => {
const min = 1
import { expect } from 'expect'
-import { FixedThreadPool, PoolEvents } from '../../../lib/index.js'
-import { TaskFunctions } from '../../test-types.js'
-import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js'
-import { DEFAULT_TASK_NAME } from '../../../lib/utils.js'
+import { FixedThreadPool, PoolEvents } from '../../../lib/index.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 {
CircularArray,
DEFAULT_CIRCULAR_ARRAY_SIZE
-} from '../../lib/circular-array.js'
+} from '../../lib/circular-array.cjs'
import {
createWorker,
getDefaultTasksQueueOptions,
updateMeasurementStatistics
-} from '../../lib/pools/utils.js'
-import { WorkerTypes } from '../../lib/index.js'
+} from '../../lib/pools/utils.cjs'
+import { WorkerTypes } from '../../lib/index.cjs'
describe('Pool utils test suite', () => {
it('Verify getDefaultTasksQueueOptions() behavior', () => {
import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads'
import { Worker as ClusterWorker } from 'node:cluster'
import { expect } from 'expect'
-import { WorkerNode } from '../../lib/pools/worker-node.js'
-import { WorkerTypes } from '../../lib/index.js'
-import { CircularArray } from '../../lib/circular-array.js'
-import { Deque } from '../../lib/deque.js'
-import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
+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 { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
describe('Worker node test suite', () => {
const threadWorkerNode = new WorkerNode(
)
const clusterWorkerNode = new WorkerNode(
WorkerTypes.cluster,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{ tasksQueueBackPressureSize: 12 }
)
-const { TaskFunctions } = require('./test-types.js')
+const { TaskFunctions } = require('./test-types.cjs')
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
return await new Promise(resolve => {
round,
secureRandom,
sleep
-} from '../lib/utils.js'
-import { KillBehaviors, WorkerTypes } from '../lib/index.js'
+} from '../lib/utils.cjs'
+import { KillBehaviors, WorkerTypes } from '../lib/index.cjs'
describe('Utils test suite', () => {
it('Verify DEFAULT_TASK_NAME value', () => {
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils.js')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
+const { sleepTaskFunction } = require('../../test-utils.cjs')
async function error (data) {
return sleepTaskFunction(
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils.js')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
+const { sleepTaskFunction } = require('../../test-utils.cjs')
async function sleep (data) {
return sleepTaskFunction(data, 2000)
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
function echo (data) {
return data
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
function test () {}
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
function error () {
throw new Error('Error Message from ClusterWorker')
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils.js')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
+const { sleepTaskFunction } = require('../../test-utils.cjs')
async function sleep (data) {
return sleepTaskFunction(data, 50000)
'use strict'
-const { ClusterWorker } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils.js')
+const { ClusterWorker } = require('../../../lib/index.cjs')
+const { sleepTaskFunction } = require('../../test-utils.cjs')
async function sleep (data) {
return sleepTaskFunction(data, 50000)
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
const {
jsonIntegerSerialization,
factorial,
fibonacci
-} = require('../../test-utils.js')
+} = require('../../test-utils.cjs')
module.exports = new ClusterWorker(
{
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { executeTaskFunction } = require('../../test-utils.js')
-const { TaskFunctions } = require('../../test-types.js')
+const { ClusterWorker, KillBehaviors } = require('../../../lib/index.cjs')
+const { executeTaskFunction } = require('../../test-utils.cjs')
+const { TaskFunctions } = require('../../test-types.cjs')
function test (data) {
data = data || {}
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
-import { sleepTaskFunction } from '../../test-utils.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
+import { sleepTaskFunction } from '../../test-utils.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
-import { sleepTaskFunction } from '../../test-utils.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
+import { sleepTaskFunction } from '../../test-utils.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
-import { sleepTaskFunction } from '../../test-utils.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
+import { sleepTaskFunction } from '../../test-utils.cjs'
/**
*
-import { ThreadWorker } from '../../../lib/index.js'
-import { sleepTaskFunction } from '../../test-utils.js'
+import { ThreadWorker } from '../../../lib/index.cjs'
+import { sleepTaskFunction } from '../../test-utils.cjs'
/**
*
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
import {
factorial,
fibonacci,
jsonIntegerSerialization
-} from '../../test-utils.js'
+} from '../../test-utils.cjs'
export default new ThreadWorker(
{
-import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
-import { executeTaskFunction } from '../../test-utils.js'
-import { TaskFunctions } from '../../test-types.js'
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs'
+import { executeTaskFunction } from '../../test-utils.cjs'
+import { TaskFunctions } from '../../test-types.cjs'
/**
*
import { expect } from 'expect'
import { restore, stub } from 'sinon'
-import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.js'
-import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.js'
+import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.cjs'
+import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.cjs'
describe('Abstract worker test suite', () => {
class StubWorkerWithMainWorker extends ThreadWorker {
import { expect } from 'expect'
import { restore, stub } from 'sinon'
-import { ClusterWorker } from '../../lib/index.js'
-import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
+import { ClusterWorker } from '../../lib/index.cjs'
+import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
describe('Cluster worker test suite', () => {
afterEach(() => {
import { expect } from 'expect'
import { restore, stub } from 'sinon'
-import { ThreadWorker } from '../../lib/index.js'
-import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
+import { ThreadWorker } from '../../lib/index.cjs'
+import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
describe('Thread worker test suite', () => {
afterEach(() => {