const factorial = n => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- // cluster worker do not support BigInt
- return factorial.toString()
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ // cluster worker do not support BigInt
+ return factorial.toString()
}
const readWriteFiles = (
return tasksArray.sort((a, b) => {
if (a[1] < b[1]) {
return -1
- } else if (a[1] > b[1]) {
+ }
+ if (a[1] > b[1]) {
return 1
}
return 0
for (const [key, value] of tasksMap) {
if (value === 0) {
return key
- } else if (value < minValue) {
+ }
+ if (value < minValue) {
minKey = key
minValue = value
}
pivotIndex = partition(array, leftIndex, rightIndex, pivotIndex, compare)
if (k === pivotIndex) {
return array[k]
- } else if (k < pivotIndex) {
+ }
+ if (k < pivotIndex) {
rightIndex = pivotIndex - 1
} else {
leftIndex = pivotIndex + 1
pivotIndex = partition(array, leftIndex, rightIndex, pivotIndex, compare)
if (k === pivotIndex) {
return array[k]
- } else if (k < pivotIndex) {
+ }
+ if (k < pivotIndex) {
return selectRecursion(array, k, leftIndex, pivotIndex - 1, compare)
- } else {
- return selectRecursion(array, k, pivotIndex + 1, rightIndex, k, compare)
}
+ return selectRecursion(array, k, pivotIndex + 1, rightIndex, k, compare)
}
/**
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
private static readonly startExpress = (
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private static readonly factorial: (n: bigint | number) => bigint = n => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
private static readonly startFastify = async (
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private static readonly factorial: (n: bigint | number) => bigint = n => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
private static readonly startWebSocketServer = (
ws.on('error', console.error)
ws.on('message', (message: RawData) => {
const { data, type } = JSON.parse(
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
message.toString()
) as MessagePayload<DataPayload>
switch (type) {
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private static readonly factorial = (n: bigint | number): bigint => {
if (n === 0 || n === 1) {
return 1n
- } else {
- n = BigInt(n)
- let factorial = 1n
- for (let i = 1n; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ n = BigInt(n)
+ let factorial = 1n
+ for (let i = 1n; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
}
private checkMessageWorkerId (message: MessageValue<Data | Response>): void {
if (message.workerId == null) {
throw new Error('Worker message received without worker id')
- } else if (this.getWorkerNodeKeyByWorkerId(message.workerId) === -1) {
+ }
+ if (this.getWorkerNodeKeyByWorkerId(message.workerId) === -1) {
throw new Error(
`Worker message received from unknown worker '${message.workerId.toString()}'`
)
throw new Error(
'Cannot instantiate a pool without specifying the number of workers'
)
- } else if (!Number.isSafeInteger(minimumNumberOfWorkers)) {
+ }
+ if (!Number.isSafeInteger(minimumNumberOfWorkers)) {
throw new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
)
- } else if (minimumNumberOfWorkers < 0) {
+ }
+ if (minimumNumberOfWorkers < 0) {
throw new RangeError(
'Cannot instantiate a pool with a negative number of workers'
)
- } else if (this.type === PoolTypes.fixed && minimumNumberOfWorkers === 0) {
+ }
+ if (this.type === PoolTypes.fixed && minimumNumberOfWorkers === 0) {
throw new RangeError('Cannot instantiate a fixed pool with zero worker')
}
}
message: MessageValue<Data>
): Promise<boolean> {
return await new Promise<boolean>((resolve, reject) => {
- const responsesReceived = new Array<MessageValue<Response>>()
+ const responsesReceived: MessageValue<Response>[] = []
const taskFunctionOperationsListener = (
message: MessageValue<Response>
): void => {
}
// CPU estimated cycle time
const numberOfDigits = cpu.speed.toString().length - 1
- const cpuCycleTime = 1 / (cpu.speed / Math.pow(10, numberOfDigits))
- cpusCycleTimeWeight += cpuCycleTime * Math.pow(10, numberOfDigits)
+ const cpuCycleTime = 1 / (cpu.speed / 10 ** numberOfDigits)
+ cpusCycleTimeWeight += cpuCycleTime * 10 ** numberOfDigits
}
return Math.round(cpusCycleTimeWeight / currentCpus.length)
}
): Required<Readonly<TasksQueueOptions>> => {
return Object.freeze({
concurrency: 1,
- size: Math.pow(poolMaxSize, 2),
+ size: poolMaxSize ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
throw new TypeError(
'Cannot instantiate a dynamic pool without specifying the maximum pool size'
)
- } else if (!Number.isSafeInteger(max)) {
+ }
+ if (!Number.isSafeInteger(max)) {
throw new TypeError(
'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
)
- } else if (min > max) {
+ }
+ if (min > max) {
throw new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
- } else if (max === 0) {
+ }
+ if (max === 0) {
throw new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
)
- } else if (min === max) {
+ }
+ if (min === max) {
throw new RangeError(
'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
)
const getWorkerType = (worker: IWorker): undefined | WorkerType => {
if (worker instanceof ThreadWorker) {
return WorkerTypes.thread
- } else if (worker instanceof ClusterWorker) {
+ }
+ if (worker instanceof ClusterWorker) {
return WorkerTypes.cluster
}
}
const getWorkerId = (worker: IWorker): number | undefined => {
if (worker instanceof ThreadWorker) {
return worker.threadId
- } else if (worker instanceof ClusterWorker) {
+ }
+ if (worker instanceof ClusterWorker) {
return worker.id
}
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
delete tail!.next
break
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- } else if (node.next === tail && tail!.next == null) {
+ }
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ if (node.next === tail && tail!.next == null) {
delete node.next
this.head = node
break
retryNumber = 0,
delayFactor = 100
): number => {
- const delay = Math.pow(2, retryNumber) * delayFactor
+ const delay = 2 ** retryNumber * delayFactor
const randomSum = delay * 0.2 * secureRandom() // 0-20% of the delay
return delay + randomSum
}
export const average = (dataSet: number[]): number => {
if (Array.isArray(dataSet) && dataSet.length === 0) {
return 0
- } else if (Array.isArray(dataSet) && dataSet.length === 1) {
+ }
+ if (Array.isArray(dataSet) && dataSet.length === 1) {
return dataSet[0]
}
return (
export const median = (dataSet: number[]): number => {
if (Array.isArray(dataSet) && dataSet.length === 0) {
return 0
- } else if (Array.isArray(dataSet) && dataSet.length === 1) {
+ }
+ if (Array.isArray(dataSet) && dataSet.length === 1) {
return dataSet[0]
}
const sortedDataSet = dataSet.slice().sort((a, b) => a - b)
* @internal
*/
export const round = (num: number, scale = 2): number => {
- const rounder = Math.pow(10, scale)
+ const rounder = 10 ** scale
return Math.round(num * rounder * (1 + Number.EPSILON)) / rounder
}
private checkMessageWorkerId (message: MessageValue<Data>): void {
if (message.workerId == null) {
throw new Error('Message worker id is not set')
- } else if (message.workerId !== this.id) {
+ }
+ if (message.workerId !== this.id) {
throw new Error(
`Message worker id ${message.workerId.toString()} does not match the worker id ${this.id.toString()}`
)
startWorkers: true,
tasksQueueOptions: {
concurrency: 2,
- size: Math.pow(numberOfWorkers, 2),
+ size: numberOfWorkers ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
expect(pool.opts.enableTasksQueue).toBe(true)
expect(pool.opts.tasksQueueOptions).toStrictEqual({
concurrency: 1,
- size: Math.pow(numberOfWorkers, 2),
+ size: numberOfWorkers ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
expect(pool.opts.enableTasksQueue).toBe(true)
expect(pool.opts.tasksQueueOptions).toStrictEqual({
concurrency: 2,
- size: Math.pow(numberOfWorkers, 2),
+ size: numberOfWorkers ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
)
expect(pool.opts.tasksQueueOptions).toStrictEqual({
concurrency: 1,
- size: Math.pow(numberOfWorkers, 2),
+ size: numberOfWorkers ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
const poolMaxSize = 4
expect(getDefaultTasksQueueOptions(poolMaxSize)).toStrictEqual({
concurrency: 1,
- size: Math.pow(poolMaxSize, 2),
+ size: poolMaxSize ** 2,
tasksFinishedTimeout: 2000,
tasksStealingOnBackPressure: true,
tasksStealingRatio: 0.6,
const factorial = n => {
if (n === 0 || n === 1) {
return 1
- } else {
- let factorial = 1
- for (let i = 1; i <= n; i++) {
- factorial *= i
- }
- return factorial
}
+ let factorial = 1
+ for (let i = 1; i <= n; i++) {
+ factorial *= i
+ }
+ return factorial
}
const executeTaskFunction = data => {