feat: add task function properties support
[poolifier.git] / src / utils.ts
index c568a29a049eda2de26cf9bd99d63e613294bc3f..7e1c8ef8ba02d6de027418d51912f56968aefb93 100644 (file)
@@ -1,6 +1,8 @@
 import { getRandomValues } from 'node:crypto'
 import * as os from 'node:os'
 
+import type { TaskFunctionProperties } from './utility-types.js'
+import type { TaskFunctionObject } from './worker/task-functions.js'
 import type { KillBehavior } from './worker/worker-options.js'
 
 /**
@@ -220,3 +222,18 @@ export const once = <A extends any[], R, C>(
     return result
   }
 }
+
+export const buildTaskFunctionProperties = <Data, Response>(
+  name: string,
+  taskFunctionObject: TaskFunctionObject<Data, Response> | undefined
+): TaskFunctionProperties => {
+  return {
+    name,
+    ...(taskFunctionObject?.priority != null && {
+      priority: taskFunctionObject.priority
+    }),
+    ...(taskFunctionObject?.strategy != null && {
+      strategy: taskFunctionObject.strategy
+    })
+  }
+}