function loopSelect (tasksMap) {
let minKey
- let minValue = Infinity
+ let minValue = Number.POSITIVE_INFINITY
for (const [key, value] of tasksMap) {
if (value === 0) {
return key
import type { URL } from 'node:url'
import type { AxiosRequestConfig } from 'axios'
-import {
- type RequestInfo as NodeFetchRequestInfo,
- type RequestInit as NodeFetchRequestInit
+import type {
+ RequestInfo as NodeFetchRequestInfo,
+ RequestInit as NodeFetchRequestInit
} from 'node-fetch'
export interface WorkerData {
application.get('/api/factorial/:number', (req: Request, res: Response) => {
const { number } = req.params
res
- .send({ number: ExpressWorker.factorial(parseInt(number)).toString() })
+ .send({
+ number: ExpressWorker.factorial(Number.parseInt(number)).toString()
+ })
.end()
})
DynamicThreadPool
} from 'poolifier'
-import {
- type ClusterWorkerData,
- type ClusterWorkerResponse,
- type DataPayload,
- type ThreadWorkerData,
- type ThreadWorkerResponse
+import type {
+ ClusterWorkerData,
+ ClusterWorkerResponse,
+ DataPayload,
+ ThreadWorkerData,
+ ThreadWorkerResponse
} from './types.js'
const emptyFunction = (): void => {
application.get('/api/factorial/:number', (req: Request, res: Response) => {
const { number } = req.params
ExpressWorker.requestHandlerPool
- .execute({ data: { number: parseInt(number) } }, 'factorial')
+ .execute({ data: { number: Number.parseInt(number) } }, 'factorial')
.then(response => {
return res.send(response.data).end()
})
import { ThreadWorker } from 'poolifier'
-import {
- type DataPayload,
- type ThreadWorkerData,
- type ThreadWorkerResponse
+import type {
+ DataPayload,
+ ThreadWorkerData,
+ ThreadWorkerResponse
} from './types.js'
class RequestHandlerWorker<
expressApp.get('/api/factorial/:number', (req: Request, res: Response) => {
const { number } = req.params
requestHandlerPool
- .execute({ body: { number: parseInt(number) } }, 'factorial')
+ .execute({ body: { number: Number.parseInt(number) } }, 'factorial')
.then(response => {
return res.send(response.body).end()
})
import { availableParallelism, DynamicThreadPool } from 'poolifier'
-import {
- type BodyPayload,
- type WorkerData,
- type WorkerResponse
-} from './types.js'
+import type { BodyPayload, WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
import { ThreadWorker } from 'poolifier'
-import {
- type BodyPayload,
- type WorkerData,
- type WorkerResponse
-} from './types.js'
+import type { BodyPayload, WorkerData, WorkerResponse } from './types.js'
class RequestHandlerWorker<
Data extends WorkerData<BodyPayload>,
import type * as fastify from 'fastify'
import type { DynamicThreadPool } from 'poolifier'
-import {
- type ThreadWorkerData,
- type ThreadWorkerResponse
-} from '../../src/types.ts'
+import type { ThreadWorkerData, ThreadWorkerResponse } from '../../src/types.ts'
declare module 'fastify' {
export interface FastifyInstance extends fastify.FastifyInstance {
import fp from 'fastify-plugin'
import { availableParallelism, DynamicThreadPool } from 'poolifier'
-import {
- type FastifyPoolifierOptions,
- type ThreadWorkerData,
- type ThreadWorkerResponse
+import type {
+ FastifyPoolifierOptions,
+ ThreadWorkerData,
+ ThreadWorkerResponse
} from './types.js'
const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
import { ThreadWorker } from 'poolifier'
-import {
- type DataPayload,
- type ThreadWorkerData,
- type ThreadWorkerResponse
+import type {
+ DataPayload,
+ ThreadWorkerData,
+ ThreadWorkerResponse
} from './types.js'
class RequestHandlerWorker<
import fp from 'fastify-plugin'
import { availableParallelism, DynamicThreadPool } from 'poolifier'
-import {
- type FastifyPoolifierOptions,
- type WorkerData,
- type WorkerResponse
+import type {
+ FastifyPoolifierOptions,
+ WorkerData,
+ WorkerResponse
} from './types.js'
const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
import { ThreadWorker } from 'poolifier'
-import {
- type BodyPayload,
- type WorkerData,
- type WorkerResponse
-} from './types.js'
+import type { BodyPayload, WorkerData, WorkerResponse } from './types.js'
class RequestHandlerWorker<
Data extends WorkerData<BodyPayload>,
import { ThreadWorker } from 'poolifier'
-import {
- type DataPayload,
- type ThreadWorkerData,
- type ThreadWorkerResponse
+import type {
+ DataPayload,
+ ThreadWorkerData,
+ ThreadWorkerResponse
} from './types.js'
class RequestHandlerWorker<
import { availableParallelism, DynamicThreadPool } from 'poolifier'
-import {
- type DataPayload,
- type WorkerData,
- type WorkerResponse
-} from './types.js'
+import type { DataPayload, WorkerData, WorkerResponse } from './types.js'
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
import { ThreadWorker } from 'poolifier'
-import {
- type DataPayload,
- type WorkerData,
- type WorkerResponse
-} from './types.js'
+import type { DataPayload, WorkerData, WorkerResponse } from './types.js'
class RequestHandlerWorker<
Data extends WorkerData<DataPayload>,
minimum: round(
min(
...this.workerNodes.map(
- workerNode => workerNode.usage.runTime.minimum ?? Infinity
+ workerNode =>
+ workerNode.usage.runTime.minimum ?? Number.POSITIVE_INFINITY
)
)
),
maximum: round(
max(
...this.workerNodes.map(
- workerNode => workerNode.usage.runTime.maximum ?? -Infinity
+ workerNode =>
+ workerNode.usage.runTime.maximum ?? Number.NEGATIVE_INFINITY
)
)
),
minimum: round(
min(
...this.workerNodes.map(
- workerNode => workerNode.usage.waitTime.minimum ?? Infinity
+ workerNode =>
+ workerNode.usage.waitTime.minimum ?? Number.POSITIVE_INFINITY
)
)
),
maximum: round(
max(
...this.workerNodes.map(
- workerNode => workerNode.usage.waitTime.maximum ?? -Infinity
+ workerNode =>
+ workerNode.usage.waitTime.maximum ?? Number.NEGATIVE_INFINITY
)
)
),
minimum: round(
min(
...this.workerNodes.map(
- workerNode => workerNode.usage.elu.idle.minimum ?? Infinity
+ workerNode =>
+ workerNode.usage.elu.idle.minimum ??
+ Number.POSITIVE_INFINITY
)
)
),
maximum: round(
max(
...this.workerNodes.map(
- workerNode => workerNode.usage.elu.idle.maximum ?? -Infinity
+ workerNode =>
+ workerNode.usage.elu.idle.maximum ??
+ Number.NEGATIVE_INFINITY
)
)
),
minimum: round(
min(
...this.workerNodes.map(
- workerNode => workerNode.usage.elu.active.minimum ?? Infinity
+ workerNode =>
+ workerNode.usage.elu.active.minimum ??
+ Number.POSITIVE_INFINITY
)
)
),
maximum: round(
max(
...this.workerNodes.map(
- workerNode => workerNode.usage.elu.active.maximum ?? -Infinity
+ workerNode =>
+ workerNode.usage.elu.active.maximum ??
+ Number.NEGATIVE_INFINITY
)
)
),
) {
workerNode.usage.runTime.aggregate = min(
...this.workerNodes.map(
- workerNode => workerNode.usage.runTime.aggregate ?? Infinity
+ workerNode =>
+ workerNode.usage.runTime.aggregate ?? Number.POSITIVE_INFINITY
)
)
}
) {
workerNode.usage.waitTime.aggregate = min(
...this.workerNodes.map(
- workerNode => workerNode.usage.waitTime.aggregate ?? Infinity
+ workerNode =>
+ workerNode.usage.waitTime.aggregate ?? Number.POSITIVE_INFINITY
)
)
}
) {
workerNode.usage.elu.active.aggregate = min(
...this.workerNodes.map(
- workerNode => workerNode.usage.elu.active.aggregate ?? Infinity
+ workerNode =>
+ workerNode.usage.elu.active.aggregate ?? Number.POSITIVE_INFINITY
)
)
}
this.pool.workerNodes[workerNodeKey]?.strategyData
?.virtualTaskEndTimestamp
const now = performance.now()
- return now < (virtualTaskEndTimestamp ?? -Infinity)
+ return now < (virtualTaskEndTimestamp ?? Number.NEGATIVE_INFINITY)
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
virtualTaskEndTimestamp!
: now
(measurementStatistics.aggregate ?? 0) + measurementValue
measurementStatistics.minimum = min(
measurementValue,
- measurementStatistics.minimum ?? Infinity
+ measurementStatistics.minimum ?? Number.POSITIVE_INFINITY
)
measurementStatistics.maximum = max(
measurementValue,
- measurementStatistics.maximum ?? -Infinity
+ measurementStatistics.maximum ?? Number.NEGATIVE_INFINITY
)
if (measurementRequirements.average || measurementRequirements.median) {
measurementStatistics.history.push(measurementValue)
* The number of filled prioritized buckets.
*/
public get buckets (): number {
- return this.bucketSize === Infinity
+ return this.bucketSize === Number.POSITIVE_INFINITY
? 1
: Math.trunc(this.nodeArray.length / this.bucketSize)
}
/**
* Constructs a priority queue.
*
- * @param bucketSize - Prioritized bucket size. @defaultValue Infinity
+ * @param bucketSize - Prioritized bucket size. @defaultValue Number.POSITIVE_INFINITY
*/
- public constructor (bucketSize = Infinity) {
- if (bucketSize !== Infinity && !Number.isSafeInteger(bucketSize)) {
+ public constructor (bucketSize = Number.POSITIVE_INFINITY) {
+ if (
+ bucketSize !== Number.POSITIVE_INFINITY &&
+ !Number.isSafeInteger(bucketSize)
+ ) {
throw new TypeError('bucketSize must be an integer')
}
if (bucketSize < 1) {
public enqueue (data: T, priority?: number): number {
priority = priority ?? 0
const startIndex =
- this.bucketSize === Infinity ? 0 : this.buckets * this.bucketSize
+ this.bucketSize === Number.POSITIVE_INFINITY
+ ? 0
+ : this.buckets * this.bucketSize
let inserted = false
for (let index = startIndex; index < this.nodeArray.length; index++) {
if (this.nodeArray[index].priority > priority) {
* @returns The dequeued data or `undefined` if the priority queue is empty.
*/
public dequeue (bucket = 0): T | undefined {
- if (this.bucketSize !== Infinity && bucket > 0) {
+ if (this.bucketSize !== Number.POSITIVE_INFINITY && bucket > 0) {
while (bucket > 0) {
const index = bucket * this.bucketSize
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
/**
* Returns the minimum of the given numbers.
- * If no numbers are given, `Infinity` is returned.
+ * If no numbers are given, `Number.POSITIVE_INFINITY` is returned.
*
* @param args - The numbers to get the minimum of.
* @returns The minimum of the given numbers.
* @internal
*/
export const min = (...args: number[]): number =>
- args.reduce((minimum, num) => (minimum < num ? minimum : num), Infinity)
+ args.reduce(
+ (minimum, num) => (minimum < num ? minimum : num),
+ Number.POSITIVE_INFINITY
+ )
/**
* Returns the maximum of the given numbers.
- * If no numbers are given, `-Infinity` is returned.
+ * If no numbers are given, `Number.NEGATIVE_INFINITY` is returned.
*
* @param args - The numbers to get the maximum of.
* @returns The maximum of the given numbers.
* @internal
*/
export const max = (...args: number[]): number =>
- args.reduce((maximum, num) => (maximum > num ? maximum : num), -Infinity)
+ args.reduce(
+ (maximum, num) => (maximum > num ? maximum : num),
+ Number.NEGATIVE_INFINITY
+ )
/**
* Wraps a function so that it can only be called once.
new RangeError('bucketSize must be greater than or equal to 1')
)
let priorityQueue = new PriorityQueue()
- expect(priorityQueue.bucketSize).toBe(Infinity)
+ expect(priorityQueue.bucketSize).toBe(Number.POSITIVE_INFINITY)
expect(priorityQueue.buckets).toBe(1)
expect(priorityQueue.size).toBe(0)
expect(priorityQueue.maxSize).toBe(0)
expect(isAsyncFunction([])).toBe(false)
expect(isAsyncFunction(new Date())).toBe(false)
// eslint-disable-next-line prefer-regex-literals
- expect(isAsyncFunction(new RegExp('[a-z]', 'i'))).toBe(false)
+ expect(isAsyncFunction(/[a-z]/i)).toBe(false)
expect(isAsyncFunction(new Error())).toBe(false)
expect(isAsyncFunction(new Map())).toBe(false)
expect(isAsyncFunction(new Set())).toBe(false)
})
it('Verify min() behavior', () => {
- expect(min()).toBe(Infinity)
+ expect(min()).toBe(Number.POSITIVE_INFINITY)
expect(min(1, 2)).toBe(1)
expect(min(2, 1)).toBe(1)
expect(min(1, 1)).toBe(1)
})
it('Verify max() behavior', () => {
- expect(max()).toBe(-Infinity)
+ expect(max()).toBe(Number.NEGATIVE_INFINITY)
expect(max(1, 2)).toBe(2)
expect(max(2, 1)).toBe(2)
expect(max(1, 1)).toBe(1)