'standard-with-typescript'
],
rules: {
- '@typescript-eslint/non-nullable-type-assertion-style': 'off',
+ 'operator-linebreak': 'off',
'tsdoc/syntax': 'warn'
}
},
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
- '@typescript-eslint/return-await': 'off'
+ // '@typescript-eslint/return-await': 'off',
+ '@typescript-eslint/no-non-null-assertion': 'off'
}
},
{
export default {
'**/*.{ts,tsx,js,jsx,cjs,mjs}': [
'biome format --write',
- 'ts-standard --fix',
'eslint --cache --fix'
],
'**/!(package.json|tsconfig.json)*.json': ['biome format --write'],
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
- "trailingComma": "none"
+ "trailingComma": "es5"
}
super({
node_fetch: async (workerData?: WorkerData) => {
const response = await nodeFetch(
- (workerData as WorkerData).input as URL | NodeFetchRequestInfo,
+ workerData!.input as URL | NodeFetchRequestInfo,
workerData?.init as NodeFetchRequestInit
)
// The response is not structured-cloneable, so we return the response text body instead.
},
fetch: async (workerData?: WorkerData) => {
const response = await fetch(
- (workerData as WorkerData).input as URL | RequestInfo,
+ workerData!.input as URL | RequestInfo,
workerData?.init as RequestInit
)
// The response is not structured-cloneable, so we return the response text body instead.
axios: async (workerData?: WorkerData) => {
const response = await axios({
method: 'get',
- url: (workerData as WorkerData).input as string,
+ url: workerData!.input as string,
...workerData?.axiosRequestConfig
})
return {
private static readonly startExpress = (
workerData?: WorkerData
): WorkerResponse => {
- const { port } = workerData as WorkerData
+ const { port } = workerData!
const application: Express = express()
workerData?: ClusterWorkerData
): ClusterWorkerResponse => {
const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
- workerData as ClusterWorkerData
+ workerData!
ExpressWorker.requestHandlerPool = new DynamicThreadPool<
ThreadWorkerData<DataPayload>,
factorial: (workerData?: Data) => {
return {
data: {
- number: RequestHandlerWorker.factorial(
- workerData?.data?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.data.number!)
}
} as unknown as Response
}
factorial: (workerData?: Data) => {
return {
body: {
- number: RequestHandlerWorker.factorial(
- workerData?.body?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.body.number!)
}
} as unknown as Response
}
private static readonly startFastify = async (
workerData?: WorkerData
): Promise<WorkerResponse> => {
- const { port } = workerData as WorkerData
+ const { port } = workerData!
FastifyWorker.fastify = Fastify({
logger: true
}
const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options
const pool = new DynamicThreadPool<ThreadWorkerData, ThreadWorkerResponse>(
- minWorkers as number,
- maxWorkers as number,
+ minWorkers!,
+ maxWorkers!,
workerFile,
poolOptions
)
private static readonly startFastify = async (
workerData?: ClusterWorkerData
): Promise<ClusterWorkerResponse> => {
- const { port, ...fastifyPoolifierOptions } = workerData as ClusterWorkerData
+ const { port, ...fastifyPoolifierOptions } = workerData!
FastifyWorker.fastify = Fastify({
logger: true
factorial: (workerData?: Data) => {
return {
data: {
- number: RequestHandlerWorker.factorial(
- workerData?.data?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.data.number!)
}
} as unknown as Response
}
}
const { workerFile, minWorkers, maxWorkers, ...poolOptions } = options
const pool = new DynamicThreadPool<WorkerData, WorkerResponse>(
- minWorkers as number,
- maxWorkers as number,
+ minWorkers!,
+ maxWorkers!,
workerFile,
poolOptions
)
factorial: (workerData?: Data) => {
return {
body: {
- number: RequestHandlerWorker.factorial(
- workerData?.body?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.body.number!)
}
} as unknown as Response
}
import { ThreadWorker } from 'poolifier'
import { createTransport } from 'nodemailer'
-import type Mail from 'nodemailer/lib/mailer/index.js'
import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'
import type { WorkerData } from './types.js'
super({
nodemailer: async (workerData?: WorkerData) => {
return await createTransport(workerData?.smtpTransport).sendMail(
- workerData?.mail as Mail.Options
+ workerData!.mail
)
}
})
private static readonly startWebSocketServer = (
workerData?: WorkerData
): WorkerResponse => {
- const { port } = workerData as WorkerData
+ const { port } = workerData!
WebSocketServerWorker.wss = new WebSocketServer({ port }, () => {
console.info(
JSON.stringify({
type: MessageType.factorial,
data: {
- number: WebSocketServerWorker.factorial(data.number as number)
+ number: WebSocketServerWorker.factorial(data.number!)
}
})
)
factorial: (workerData?: Data) => {
return {
data: {
- number: RequestHandlerWorker.factorial(
- workerData?.data?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.data.number!)
}
} as unknown as Response
}
workerData?: ClusterWorkerData
): ClusterWorkerResponse => {
const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } =
- workerData as ClusterWorkerData
+ workerData!
WebSocketServerWorker.requestHandlerPool = new DynamicThreadPool<
ThreadWorkerData<DataPayload>,
factorial: (workerData?: Data) => {
return {
data: {
- number: RequestHandlerWorker.factorial(
- workerData?.data?.number as number
- )
+ number: RequestHandlerWorker.factorial(workerData!.data.number!)
}
} as unknown as Response
}
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^46.9.1",
- "eslint-plugin-n": "^16.5.0",
+ "eslint-plugin-n": "^16.6.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-spellcheck": "^0.0.20",
"eslint-plugin-tsdoc": "^0.2.17",
version: 8.56.0
eslint-config-standard:
specifier: ^17.1.0
- version: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
+ version: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
eslint-config-standard-with-typescript:
specifier: ^43.0.0
- version: 43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3)
+ version: 43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3)
eslint-define-config:
specifier: ^2.1.0
version: 2.1.0
specifier: ^46.9.1
version: 46.9.1(eslint@8.56.0)
eslint-plugin-n:
- specifier: ^16.5.0
- version: 16.5.0(eslint@8.56.0)
+ specifier: ^16.6.0
+ version: 16.6.0(eslint@8.56.0)
eslint-plugin-promise:
specifier: ^6.1.1
version: 6.1.1(eslint@8.56.0)
through: 2.3.8
dev: true
- /acorn-jsx@5.3.2(acorn@8.11.2):
+ /acorn-jsx@5.3.2(acorn@8.11.3):
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
peerDependencies:
acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
dependencies:
- acorn: 8.11.2
+ acorn: 8.11.3
dev: true
- /acorn@8.11.2:
- resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
+ /acorn@8.11.3:
+ resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==}
engines: {node: '>=0.4.0'}
hasBin: true
dev: true
- supports-color
dev: true
- /eslint-config-standard-with-typescript@43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3):
+ /eslint-config-standard-with-typescript@43.0.0(@typescript-eslint/eslint-plugin@6.16.0)(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)(typescript@5.3.3):
resolution: {integrity: sha512-AT0qK01M5bmsWiE3UZvaQO5da1y1n6uQckAKqGNe6zPW5IOzgMLXZxw77nnFm+C11nxAZXsCPrbsgJhSrGfX6Q==}
peerDependencies:
'@typescript-eslint/eslint-plugin': ^6.4.0
'@typescript-eslint/eslint-plugin': 6.16.0(@typescript-eslint/parser@6.16.0)(eslint@8.56.0)(typescript@5.3.3)
'@typescript-eslint/parser': 6.16.0(eslint@8.56.0)(typescript@5.3.3)
eslint: 8.56.0
- eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
+ eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0)
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0)
- eslint-plugin-n: 16.5.0(eslint@8.56.0)
+ eslint-plugin-n: 16.6.0(eslint@8.56.0)
eslint-plugin-promise: 6.1.1(eslint@8.56.0)
typescript: 5.3.3
transitivePeerDependencies:
eslint-plugin-promise: 6.1.1(eslint@8.56.0)
dev: true
- /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.5.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0):
+ /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@16.6.0)(eslint-plugin-promise@6.1.1)(eslint@8.56.0):
resolution: {integrity: sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==}
engines: {node: '>=12.0.0'}
peerDependencies:
dependencies:
eslint: 8.56.0
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0)
- eslint-plugin-n: 16.5.0(eslint@8.56.0)
+ eslint-plugin-n: 16.6.0(eslint@8.56.0)
eslint-plugin-promise: 6.1.1(eslint@8.56.0)
dev: true
semver: 7.5.4
dev: true
- /eslint-plugin-n@16.5.0(eslint@8.56.0):
- resolution: {integrity: sha512-Hw02Bj1QrZIlKyj471Tb1jSReTl4ghIMHGuBGiMVmw+s0jOPbI4CBuYpGbZr+tdQ+VAvSK6FDSta3J4ib/SKHQ==}
+ /eslint-plugin-n@16.6.0(eslint@8.56.0):
+ resolution: {integrity: sha512-Ag3tYFF90lYU8JdHEl9qSSpeLYbVnO+Oj7sgPUarWUacv1mPL3d5h5yG4Bv3tLe71hrcxmgTi7oByYwKXaVatw==}
engines: {node: '>=16.0.0'}
peerDependencies:
eslint: '>=7.0.0'
eslint: 8.56.0
eslint-plugin-es-x: 7.5.0(eslint@8.56.0)
get-tsconfig: 4.7.2
+ globals: 13.24.0
ignore: 5.3.0
is-builtin-module: 3.2.1
is-core-module: 2.13.1
resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
- acorn: 8.11.2
- acorn-jsx: 5.3.2(acorn@8.11.2)
+ acorn: 8.11.3
+ acorn-jsx: 5.3.2(acorn@8.11.3)
eslint-visitor-keys: 3.4.3
dev: true
hasBin: true
dependencies:
'@jridgewell/source-map': 0.3.5
- acorn: 8.11.2
+ acorn: 8.11.3
commander: 2.20.3
source-map-support: 0.5.21
dev: true
return
}
const tail = this.tail
- this.tail = (this.tail as Node<T>).prev
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.tail = this.tail!.prev
if (this.tail == null) {
delete this.head
} else {
value: node.data,
done: false
}
- node = node.next as Node<T>
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ node = node.next!
return ret
}
}
value: node.data,
done: false
}
- node = node.prev as Node<T>
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ node = node.prev!
return ret
}
}
import type {
IWorker,
IWorkerNode,
- TaskStatistics,
WorkerInfo,
WorkerNodeEventDetail,
- WorkerType,
- WorkerUsage
+ WorkerType
} from './worker.js'
import {
Measurements,
private checkPoolOptions (opts: PoolOptions<Worker>): void {
if (isPlainObject(opts)) {
this.opts.startWorkers = opts.startWorkers ?? true
- checkValidWorkerChoiceStrategy(
- opts.workerChoiceStrategy as WorkerChoiceStrategy
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ checkValidWorkerChoiceStrategy(opts.workerChoiceStrategy!)
this.opts.workerChoiceStrategy =
opts.workerChoiceStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN
this.checkValidWorkerChoiceStrategyOptions(
- opts.workerChoiceStrategyOptions as WorkerChoiceStrategyOptions
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts.workerChoiceStrategyOptions!
)
if (opts.workerChoiceStrategyOptions != null) {
this.opts.workerChoiceStrategyOptions = opts.workerChoiceStrategyOptions
this.opts.enableEvents = opts.enableEvents ?? true
this.opts.enableTasksQueue = opts.enableTasksQueue ?? false
if (this.opts.enableTasksQueue) {
- checkValidTasksQueueOptions(opts.tasksQueueOptions as TasksQueueOptions)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ checkValidTasksQueueOptions(opts.tasksQueueOptions!)
this.opts.tasksQueueOptions = this.buildTasksQueueOptions(
- opts.tasksQueueOptions as TasksQueueOptions
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts.tasksQueueOptions!
)
}
} else {
worker: this.worker,
started: this.started,
ready: this.ready,
- strategy: this.opts.workerChoiceStrategy as WorkerChoiceStrategy,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ strategy: this.opts.workerChoiceStrategy!,
minSize: this.minimumNumberOfWorkers,
maxSize: this.maximumNumberOfWorkers ?? this.minimumNumberOfWorkers,
...(this.workerChoiceStrategyContext?.getTaskStatisticsRequirements()
this.flushTasksQueues()
}
this.opts.enableTasksQueue = enable
- this.setTasksQueueOptions(tasksQueueOptions as TasksQueueOptions)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.setTasksQueueOptions(tasksQueueOptions!)
}
/** @inheritDoc */
checkValidTasksQueueOptions(tasksQueueOptions)
this.opts.tasksQueueOptions =
this.buildTasksQueueOptions(tasksQueueOptions)
- this.setTasksQueueSize(this.opts.tasksQueueOptions.size as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.setTasksQueueSize(this.opts.tasksQueueOptions.size!)
if (this.opts.tasksQueueOptions.taskStealing === true) {
this.unsetTaskStealing()
this.setTaskStealing()
workerNode =>
workerNode.info.ready &&
workerNode.usage.tasks.executing <
- (this.opts.tasksQueueOptions?.concurrency as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.tasksQueueOptions!.concurrency!
) === -1
)
}
if (this.opts.enableTasksQueue === true) {
return (
this.workerNodes[workerNodeKey].usage.tasks.executing >=
- (this.opts.tasksQueueOptions?.concurrency as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.tasksQueueOptions!.concurrency!
)
}
return this.workerNodes[workerNodeKey].usage.tasks.executing > 0
message: MessageValue<Response>
): void => {
this.checkMessageWorkerId(message)
- const workerId = this.getWorkerInfo(workerNodeKey).id as number
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const workerId = this.getWorkerInfo(workerNodeKey).id!
if (
message.taskFunctionOperationStatus != null &&
message.workerId === workerId
new Error(
`Task function operation '${
message.taskFunctionOperation as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
}' failed on worker ${message.workerId} with error: '${
- message.workerError?.message as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ message.workerError!.message
}'`
)
)
new Error(
`Task function operation '${
message.taskFunctionOperation as string
- }' failed on worker ${
- errorResponse?.workerId as number
- } with error: '${
- errorResponse?.workerError?.message as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ }' failed on worker ${errorResponse!
+ .workerId!} with error: '${
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ errorResponse!.workerError!.message
}'`
)
)
return (
this.tasksQueueSize(workerNodeKey) === 0 &&
this.workerNodes[workerNodeKey].usage.tasks.executing <
- (this.opts.tasksQueueOptions?.concurrency as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.tasksQueueOptions!.concurrency!
)
}
timestamp,
taskId: randomUUID()
}
- this.promiseResponseMap.set(task.taskId as string, {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.promiseResponseMap.set(task.taskId!, {
resolve,
reject,
workerNodeKey,
} else if (message.kill === 'failure') {
reject(
new Error(
- `Kill message handling failed on worker ${
- message.workerId as number
- }`
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ `Kill message handling failed on worker ${message.workerId!}`
)
)
}
}
if (
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
- this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(
- task.name as string
- ) != null
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(task.name!) !=
+ null
) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const taskFunctionWorkerUsage = this.workerNodes[
workerNodeKey
- ].getTaskFunctionWorkerUsage(task.name as string) as WorkerUsage
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ ].getTaskFunctionWorkerUsage(task.name!)!
++taskFunctionWorkerUsage.tasks.executing
updateWaitTimeWorkerUsage(
this.workerChoiceStrategyContext,
if (
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
this.workerNodes[workerNodeKey].getTaskFunctionWorkerUsage(
- message.taskPerformance?.name as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ message.taskPerformance!.name
) != null
) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const taskFunctionWorkerUsage = this.workerNodes[
workerNodeKey
- ].getTaskFunctionWorkerUsage(
- message.taskPerformance?.name as string
- ) as WorkerUsage
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ ].getTaskFunctionWorkerUsage(message.taskPerformance!.name)!
updateTaskStatisticsWorkerUsage(taskFunctionWorkerUsage, message)
updateRunTimeWorkerUsage(
this.workerChoiceStrategyContext,
)
this.handleTask(
destinationWorkerNodeKey,
- this.dequeueTask(workerNodeKey) as Task<Data>
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.dequeueTask(workerNodeKey)!
)
}
}
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
workerNode.getTaskFunctionWorkerUsage(taskName) != null
) {
- const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
- taskName
- ) as WorkerUsage
+ const taskFunctionWorkerUsage =
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerNode.getTaskFunctionWorkerUsage(taskName)!
++taskFunctionWorkerUsage.tasks.stolen
}
}
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
workerNode.getTaskFunctionWorkerUsage(taskName) != null
) {
- const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
- taskName
- ) as WorkerUsage
+ const taskFunctionWorkerUsage =
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerNode.getTaskFunctionWorkerUsage(taskName)!
++taskFunctionWorkerUsage.tasks.sequentiallyStolen
}
}
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
workerNode.getTaskFunctionWorkerUsage(taskName) != null
) {
- const taskFunctionWorkerUsage = workerNode.getTaskFunctionWorkerUsage(
- taskName
- ) as WorkerUsage
+ const taskFunctionWorkerUsage =
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerNode.getTaskFunctionWorkerUsage(taskName)!
taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0
}
}
}
if (
this.cannotStealTask() ||
- (this.info.stealingWorkerNodes as number) >
- Math.floor(this.workerNodes.length / 2)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.info.stealingWorkerNodes! > Math.floor(this.workerNodes.length / 2)
) {
if (previousStolenTask != null) {
this.getWorkerInfo(workerNodeKey).stealing = false
this.tasksQueueSize(workerNodeKey) > 0)
) {
this.getWorkerInfo(workerNodeKey).stealing = false
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const taskName of this.workerNodes[workerNodeKey].info
- .taskFunctionNames as string[]) {
+ .taskFunctionNames!) {
this.resetTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
workerNodeKey,
taskName
this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) &&
stolenTask != null
) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const taskFunctionTasksWorkerUsage = this.workerNodes[
workerNodeKey
- ].getTaskFunctionWorkerUsage(stolenTask.name as string)
- ?.tasks as TaskStatistics
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ ].getTaskFunctionWorkerUsage(stolenTask.name!)!.tasks
if (
taskFunctionTasksWorkerUsage.sequentiallyStolen === 0 ||
(previousStolenTask != null &&
) {
this.updateTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
workerNodeKey,
- stolenTask.name as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ stolenTask.name!
)
} else {
this.resetTaskSequentiallyStolenStatisticsTaskFunctionWorkerUsage(
workerNodeKey,
- stolenTask.name as string
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ stolenTask.name!
)
}
}
sourceWorkerNode.usage.tasks.queued > 0
)
if (sourceWorkerNode != null) {
- const task = sourceWorkerNode.popTask() as Task<Data>
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const task = sourceWorkerNode.popTask()!
this.handleTask(workerNodeKey, task)
this.updateTaskSequentiallyStolenStatisticsWorkerUsage(workerNodeKey)
- this.updateTaskStolenStatisticsWorkerUsage(
- workerNodeKey,
- task.name as string
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.updateTaskStolenStatisticsWorkerUsage(workerNodeKey, task.name!)
return task
}
}
): void => {
if (
this.cannotStealTask() ||
- (this.info.stealingWorkerNodes as number) >
- Math.floor(this.workerNodes.length / 2)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.info.stealingWorkerNodes! > Math.floor(this.workerNodes.length / 2)
) {
return
}
const { workerId } = eventDetail
const sizeOffset = 1
- if ((this.opts.tasksQueueOptions?.size as number) <= sizeOffset) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (this.opts.tasksQueueOptions!.size! <= sizeOffset) {
return
}
const sourceWorkerNode =
!workerNode.info.stealing &&
workerNode.info.id !== workerId &&
workerNode.usage.tasks.queued <
- (this.opts.tasksQueueOptions?.size as number) - sizeOffset
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.tasksQueueOptions!.size! - sizeOffset
) {
this.getWorkerInfo(workerNodeKey).stealing = true
- const task = sourceWorkerNode.popTask() as Task<Data>
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const task = sourceWorkerNode.popTask()!
this.handleTask(workerNodeKey, task)
- this.updateTaskStolenStatisticsWorkerUsage(
- workerNodeKey,
- task.name as string
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.updateTaskStolenStatisticsWorkerUsage(workerNodeKey, task.name!)
this.getWorkerInfo(workerNodeKey).stealing = false
}
}
private handleWorkerReadyResponse (message: MessageValue<Response>): void {
const { workerId, ready, taskFunctionNames } = message
if (ready === false) {
- throw new Error(`Worker ${workerId as number} failed to initialize`)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ throw new Error(`Worker ${workerId!} failed to initialize`)
}
const workerInfo = this.getWorkerInfo(
this.getWorkerNodeKeyByWorkerId(workerId)
private handleTaskExecutionResponse (message: MessageValue<Response>): void {
const { workerId, taskId, workerError, data } = message
- const promiseResponse = this.promiseResponseMap.get(taskId as string)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const promiseResponse = this.promiseResponseMap.get(taskId!)
if (promiseResponse != null) {
const { resolve, reject, workerNodeKey, asyncResource } = promiseResponse
const workerNode = this.workerNodes[workerNodeKey]
}
asyncResource?.emitDestroy()
this.afterTaskExecutionHook(workerNodeKey, message)
- this.promiseResponseMap.delete(taskId as string)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.promiseResponseMap.delete(taskId!)
workerNode?.emit('taskFinished', taskId)
if (this.opts.enableTasksQueue === true && !this.destroying) {
const workerNodeTasksUsage = workerNode.usage.tasks
if (
this.tasksQueueSize(workerNodeKey) > 0 &&
workerNodeTasksUsage.executing <
- (this.opts.tasksQueueOptions?.concurrency as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.tasksQueueOptions!.concurrency!
) {
- this.executeTask(
- workerNodeKey,
- this.dequeueTask(workerNodeKey) as Task<Data>
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.executeTask(workerNodeKey, this.dequeueTask(workerNodeKey)!)
}
if (
workerNodeTasksUsage.executing === 0 &&
workerNodeTasksUsage.sequentiallyStolen === 0
) {
workerNode.emit('idleWorkerNode', {
- workerId: workerId as number,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerId: workerId!,
workerNodeKey
})
}
protected flushTasksQueue (workerNodeKey: number): number {
let flushedTasks = 0
while (this.tasksQueueSize(workerNodeKey) > 0) {
- this.executeTask(
- workerNodeKey,
- this.dequeueTask(workerNodeKey) as Task<Data>
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.executeTask(workerNodeKey, this.dequeueTask(workerNodeKey)!)
++flushedTasks
}
this.workerNodes[workerNodeKey].clearTasksQueue()
super(min, filePath, opts, max)
checkDynamicPoolSize(
this.minimumNumberOfWorkers,
- this.maximumNumberOfWorkers as number
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.maximumNumberOfWorkers!
)
}
): void {
this.workerNodes[workerNodeKey].worker.send({
...message,
- workerId: this.getWorkerInfo(workerNodeKey).id as number
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerId: this.getWorkerInfo(workerNodeKey).id!
})
}
): void {
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.runTime,
- opts.runTime?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts.runTime!.median
)
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.waitTime,
- opts.waitTime?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts.waitTime!.median
)
this.toggleMedianMeasurementStatisticsRequirements(
this.taskStatisticsRequirements.elu,
- opts.elu?.median as boolean
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ opts.elu!.median
)
}
* Check the next worker node readiness.
*/
protected checkNextWorkerNodeReadiness (): void {
- if (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number)) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
delete this.nextWorkerNodeKey
}
}
import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils.js'
import type { IPool } from '../pool.js'
-import type { IWorker, StrategyData } from '../worker.js'
+import type { IWorker } from '../worker.js'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js'
import {
type IWorkerChoiceStrategy,
}
}
return this.isWorkerNodeReady(workerNodeKey) &&
- (workerNode.strategyData.virtualTaskEndTimestamp as number) <
- ((workerNodes[minWorkerNodeKey].strategyData as StrategyData)
- .virtualTaskEndTimestamp as number)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerNode.strategyData.virtualTaskEndTimestamp! <
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerNodes[minWorkerNodeKey].strategyData!.virtualTaskEndTimestamp!
? workerNodeKey
: minWorkerNodeKey
},
?.virtualTaskEndTimestamp
const now = performance.now()
return now < (virtualTaskEndTimestamp ?? -Infinity)
- ? (virtualTaskEndTimestamp as number)
+ ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ virtualTaskEndTimestamp!
: now
}
}
) {
this.workerNodeVirtualTaskRunTime = 0
}
- const workerWeight = this.opts.weights?.[workerNodeKey] as number
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const workerWeight = this.opts.weights![workerNodeKey]!
if (
this.isWorkerNodeReady(workerNodeKey) &&
workerWeight >= this.roundWeights[roundIndex] &&
private getRoundWeights (): number[] {
return [
...new Set(
- Object.values(this.opts.weights as Record<number, number>)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ Object.values(this.opts.weights!)
.slice()
.sort((a, b) => a - b)
)
}
private weightedRoundRobinNextWorkerNodeKey (): number | undefined {
- const workerWeight = this.opts.weights?.[
- this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
- ] as number
+ const workerWeight =
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.opts.weights![this.nextWorkerNodeKey ?? this.previousWorkerNodeKey]!
if (this.workerNodeVirtualTaskRunTime < workerWeight) {
this.workerNodeVirtualTaskRunTime =
this.workerNodeVirtualTaskRunTime +
* @returns The strategy policy.
*/
public getStrategyPolicy (): StrategyPolicy {
- return (
- this.workerChoiceStrategies.get(
- this.workerChoiceStrategy
- ) as IWorkerChoiceStrategy
- ).strategyPolicy
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return this.workerChoiceStrategies.get(this.workerChoiceStrategy)!
+ .strategyPolicy
}
/**
* @returns The task statistics requirements.
*/
public getTaskStatisticsRequirements (): TaskStatisticsRequirements {
- return (
- this.workerChoiceStrategies.get(
- this.workerChoiceStrategy
- ) as IWorkerChoiceStrategy
- ).taskStatisticsRequirements
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return this.workerChoiceStrategies.get(this.workerChoiceStrategy)!
+ .taskStatisticsRequirements
}
/**
* @returns `true` if the update is successful, `false` otherwise.
*/
public update (workerNodeKey: number): boolean {
- return (
- this.workerChoiceStrategies.get(
- this.workerChoiceStrategy
- ) as IWorkerChoiceStrategy
- ).update(workerNodeKey)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return this.workerChoiceStrategies
+ .get(this.workerChoiceStrategy)!
+ .update(workerNodeKey)
}
/**
* @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined.
*/
public execute (): number {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const workerChoiceStrategy = this.workerChoiceStrategies.get(
this.workerChoiceStrategy
- ) as IWorkerChoiceStrategy
+ )!
if (!workerChoiceStrategy.hasPoolWorkerNodesReady()) {
return this.execute()
}
retriesCount++
}
chooseCount++
- } while (
- workerNodeKey == null &&
- retriesCount < (this.opts?.retries as number)
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ } while (workerNodeKey == null && retriesCount < this.opts!.retries!)
if (workerNodeKey == null) {
throw new Error(
`Worker node key chosen is null or undefined after ${retriesCount} retries`
* @returns `true` if the removal is successful, `false` otherwise.
*/
public remove (workerNodeKey: number): boolean {
- return (
- this.workerChoiceStrategies.get(
- this.workerChoiceStrategy
- ) as IWorkerChoiceStrategy
- ).remove(workerNodeKey)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ return this.workerChoiceStrategies
+ .get(this.workerChoiceStrategy)!
+ .remove(workerNodeKey)
}
/**
super(min, filePath, opts, max)
checkDynamicPoolSize(
this.minimumNumberOfWorkers,
- this.maximumNumberOfWorkers as number
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.maximumNumberOfWorkers!
)
}
import {
- type MessageChannel,
type MessagePort,
type TransferListItem,
type Worker,
/** @inheritDoc */
protected sendStartupMessageToWorker (workerNodeKey: number): void {
const workerNode = this.workerNodes[workerNodeKey]
- const port2: MessagePort = (workerNode.messageChannel as MessageChannel)
- .port2
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const port2: MessagePort = workerNode.messageChannel!.port2
workerNode.worker.postMessage(
{
ready: false,
const tasksQueueSize = this.tasksQueue.push(task)
if (this.hasBackPressure() && !this.onBackPressureStarted) {
this.onBackPressureStarted = true
- this.emit('backPressure', { workerId: this.info.id as number })
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.emit('backPressure', { workerId: this.info.id! })
this.onBackPressureStarted = false
}
return tasksQueueSize
const tasksQueueSize = this.tasksQueue.unshift(task)
if (this.hasBackPressure() && !this.onBackPressureStarted) {
this.onBackPressureStarted = true
- this.emit('backPressure', { workerId: this.info.id as number })
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.emit('backPressure', { workerId: this.info.id! })
this.onBackPressureStarted = false
}
return tasksQueueSize
private initWorkerInfo (worker: Worker): WorkerInfo {
return {
id: getWorkerId(worker),
- type: getWorkerType(worker) as WorkerType,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ type: getWorkerType(worker)!,
dynamic: false,
ready: false,
stealing: false
for (const task of this.tasksQueue) {
if (
(task.name === DEFAULT_TASK_NAME &&
- name === (this.info.taskFunctionNames as string[])[1]) ||
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ name === this.info.taskFunctionNames![1]) ||
(task.name !== DEFAULT_TASK_NAME && name === task.name)
) {
++taskFunctionQueueSize
'Cannot set the default task function to a non-existing task function'
)
}
- this.taskFunctions.set(
- DEFAULT_TASK_NAME,
- this.taskFunctions.get(name) as TaskFunction<Data, Response>
- )
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.taskFunctions.set(DEFAULT_TASK_NAME, this.taskFunctions.get(name)!)
this.sendTaskFunctionNamesToMainWorker()
return { status: true }
} catch (error) {
switch (taskFunctionOperation) {
case 'add':
response = this.addTaskFunction(
- taskFunctionName as string,
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
- new Function(`return ${taskFunction as string}`)() as TaskFunction<
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ taskFunctionName!,
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func, @typescript-eslint/no-non-null-assertion
+ new Function(`return ${taskFunction!}`)() as TaskFunction<
Data,
Response
>
)
break
case 'remove':
- response = this.removeTaskFunction(taskFunctionName as string)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ response = this.removeTaskFunction(taskFunctionName!)
break
case 'default':
- response = this.setDefaultTaskFunction(taskFunctionName as string)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ response = this.setDefaultTaskFunction(taskFunctionName!)
break
default:
response = { status: false, error: new Error('Unknown task operation') }
...(!response.status &&
response?.error != null && {
workerError: {
- name: taskFunctionName as string,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ name: taskFunctionName!,
message: this.handleError(response.error as Error | string)
}
})
if (!this.taskFunctions.has(taskFunctionName)) {
this.sendToMainWorker({
workerError: {
- name: name as string,
- message: `Task function '${name as string}' not found`,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ name: name!,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ message: `Task function '${name!}' not found`,
data
},
taskId
} catch (error) {
this.sendToMainWorker({
workerError: {
- name: name as string,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ name: name!,
message: this.handleError(error as Error | string),
data
},
.catch(error => {
this.sendToMainWorker({
workerError: {
- name: name as string,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ name: name!,
message: this.handleError(error as Error | string),
data
},
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
opts: WorkerOptions = {}
) {
- super(cluster.isPrimary, cluster.worker as Worker, taskFunctions, opts)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ super(cluster.isPrimary, cluster.worker!, taskFunctions, opts)
}
/** @inheritDoc */
taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
opts: WorkerOptions = {}
) {
- super(isMainThread, parentPort as MessagePort, taskFunctions, opts)
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ super(isMainThread, parentPort!, taskFunctions, opts)
}
/** @inheritDoc */