test: cleanup helpers
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
index 0fbb4d4d43165737d3bd3c0c7378b2c55d7e03d2..ac2ee6c3ca6b97f96c0e16a8ccf04e9557246090 100644 (file)
@@ -41,10 +41,24 @@ export const WorkerChoiceStrategies = Object.freeze({
  */
 export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
 
+/**
+ * Enumeration of measurements.
+ */
+export const Measurements = Object.freeze({
+  runTime: 'runTime',
+  waitTime: 'waitTime',
+  elu: 'elu'
+} as const)
+
+/**
+ * Measurement.
+ */
+export type Measurement = keyof typeof Measurements
+
 /**
  * Measurement options.
  */
-interface MeasurementOptions {
+export interface MeasurementOptions {
   /**
    * Set measurement median.
    */
@@ -55,6 +69,10 @@ interface MeasurementOptions {
  * Worker choice strategy options.
  */
 export interface WorkerChoiceStrategyOptions {
+  /**
+   * Measurement to use for worker choice strategy.
+   */
+  measurement?: Measurement
   /**
    * Runtime options.
    *
@@ -67,6 +85,12 @@ export interface WorkerChoiceStrategyOptions {
    * @defaultValue \{ median: false \}
    */
   waitTime?: MeasurementOptions
+  /**
+   * Event loop utilization options.
+   *
+   * @defaultValue \{ median: false \}
+   */
+  elu?: MeasurementOptions
   /**
    * Worker weights to use for weighted round robin worker selection strategy.
    * Weight is the tasks maximum average or median runtime in milliseconds.
@@ -81,7 +105,7 @@ export interface WorkerChoiceStrategyOptions {
  *
  * @internal
  */
-interface MeasurementStatisticsRequirements {
+export interface MeasurementStatisticsRequirements {
   /**
    * Require measurement aggregate.
    */
@@ -111,15 +135,31 @@ export interface TaskStatisticsRequirements {
    */
   waitTime: MeasurementStatisticsRequirements
   /**
-   * Event loop utilization.
+   * Tasks event loop utilization requirements.
    */
-  elu: boolean
+  elu: MeasurementStatisticsRequirements
+}
+
+/**
+ * Strategy policy.
+ *
+ * @internal
+ */
+export interface StrategyPolicy {
+  /**
+   * Expects direct usage of dynamic worker.
+   */
+  useDynamicWorker: boolean
 }
 
 /**
  * Worker choice strategy interface.
  */
 export interface IWorkerChoiceStrategy {
+  /**
+   * Strategy policy.
+   */
+  readonly strategyPolicy: StrategyPolicy
   /**
    * Tasks statistics requirements.
    */