Skip to content

Commit 5d006d9

Browse files
committed
refactor: flag some object literals as read only
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 5244d20 commit 5d006d9

8 files changed

+30
-27
lines changed

src/pools/selection-strategies/abstract-worker-choice-strategy.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export abstract class AbstractWorkerChoiceStrategy<
4141
}
4242

4343
/** @inheritDoc */
44-
public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
45-
runTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
46-
waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
47-
elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
48-
}
44+
public readonly taskStatisticsRequirements: TaskStatisticsRequirements =
45+
Object.freeze({
46+
runTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
47+
waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
48+
elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
49+
})
4950

5051
/**
5152
* Constructs a worker choice strategy bound to the pool.

src/pools/selection-strategies/fair-share-worker-choice-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class FairShareWorkerChoiceStrategy<
2323
implements IWorkerChoiceStrategy {
2424
/** @inheritDoc */
2525
public override readonly taskStatisticsRequirements:
26-
TaskStatisticsRequirements = {
26+
TaskStatisticsRequirements = Object.freeze({
2727
runTime: {
2828
aggregate: true,
2929
average: true,
@@ -39,7 +39,7 @@ export class FairShareWorkerChoiceStrategy<
3939
average: true,
4040
median: false,
4141
},
42-
}
42+
})
4343

4444
/** @inheritDoc */
4545
public constructor(

src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
2323
implements IWorkerChoiceStrategy {
2424
/** @inheritDoc */
2525
public override readonly taskStatisticsRequirements:
26-
TaskStatisticsRequirements = {
26+
TaskStatisticsRequirements = Object.freeze({
2727
runTime: {
2828
aggregate: true,
2929
average: true,
@@ -35,7 +35,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
3535
median: false,
3636
},
3737
elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
38-
}
38+
})
3939

4040
/**
4141
* Round id.

src/pools/selection-strategies/least-busy-worker-choice-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class LeastBusyWorkerChoiceStrategy<
2323
implements IWorkerChoiceStrategy {
2424
/** @inheritDoc */
2525
public override readonly taskStatisticsRequirements:
26-
TaskStatisticsRequirements = {
26+
TaskStatisticsRequirements = Object.freeze({
2727
runTime: {
2828
aggregate: true,
2929
average: false,
@@ -35,7 +35,7 @@ export class LeastBusyWorkerChoiceStrategy<
3535
median: false,
3636
},
3737
elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
38-
}
38+
})
3939

4040
/** @inheritDoc */
4141
public constructor(

src/pools/selection-strategies/least-elu-worker-choice-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export class LeastEluWorkerChoiceStrategy<
2323
implements IWorkerChoiceStrategy {
2424
/** @inheritDoc */
2525
public override readonly taskStatisticsRequirements:
26-
TaskStatisticsRequirements = {
26+
TaskStatisticsRequirements = Object.freeze({
2727
runTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
2828
waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
2929
elu: {
3030
aggregate: true,
3131
average: false,
3232
median: false,
3333
},
34-
}
34+
})
3535

3636
/** @inheritDoc */
3737
public constructor(

src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
2424
implements IWorkerChoiceStrategy {
2525
/** @inheritDoc */
2626
public override readonly taskStatisticsRequirements:
27-
TaskStatisticsRequirements = {
27+
TaskStatisticsRequirements = Object.freeze({
2828
runTime: {
2929
aggregate: true,
3030
average: true,
@@ -36,7 +36,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
3636
median: false,
3737
},
3838
elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
39-
}
39+
})
4040

4141
/**
4242
* Worker node virtual task execution time.

src/pools/utils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,25 @@ export { exportedUpdateMeasurementStatistics }
3636
/**
3737
* Default measurement statistics requirements.
3838
*/
39-
export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS:
40-
MeasurementStatisticsRequirements = {
41-
aggregate: false,
42-
average: false,
43-
median: false,
44-
}
39+
export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: Readonly<
40+
MeasurementStatisticsRequirements
41+
> = Object.freeze({
42+
aggregate: false,
43+
average: false,
44+
median: false,
45+
})
4546

4647
export const getDefaultTasksQueueOptions = (
4748
poolMaxSize: number,
48-
): Required<TasksQueueOptions> => {
49-
return {
49+
): Required<Readonly<TasksQueueOptions>> => {
50+
return Object.freeze({
5051
size: Math.pow(poolMaxSize, 2),
5152
concurrency: 1,
5253
taskStealing: true,
5354
tasksStealingOnBackPressure: true,
5455
tasksStealingRatio: 0.6,
5556
tasksFinishedTimeout: 2000,
56-
}
57+
})
5758
}
5859

5960
export const checkFileURL = (fileURL: URL | undefined): void => {

src/worker/abstract-worker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { KillBehaviors, type WorkerOptions } from './worker-options.ts'
2929

3030
const DEFAULT_MAX_INACTIVE_TIME = 60000
31-
const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
31+
const DEFAULT_WORKER_OPTIONS: Readonly<WorkerOptions> = Object.freeze({
3232
/**
3333
* The kill behavior option on this worker or its default value.
3434
*/
@@ -42,7 +42,7 @@ const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
4242
* The function to call when the worker is killed.
4343
*/
4444
killHandler: EMPTY_FUNCTION,
45-
}
45+
})
4646

4747
/**
4848
* Base class that implements some shared logic for all poolifier workers.
@@ -59,7 +59,8 @@ export abstract class AbstractWorker<
5959
/**
6060
* Worker id.
6161
*/
62-
protected abstract id?: `${string}-${string}-${string}-${string}-${string}`
62+
protected abstract readonly id?:
63+
`${string}-${string}-${string}-${string}-${string}`
6364
/**
6465
* Task function(s) object processed by the worker when the pool's `execute` method is invoked.
6566
*/

0 commit comments

Comments
 (0)