X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futility-types.ts;h=08861ebd30045ae430de21eae055f9634a007341;hb=dab8c377b70fc962ec217f2aeb719842f9f94cd6;hp=81a57698f5fa6a7dc5e631cbdec844ee68c44c2c;hpb=48ef910747c7eafb18ebfff83d8eb24e5f5be26c;p=poolifier.git diff --git a/src/utility-types.ts b/src/utility-types.ts index 81a57698..08861ebd 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -19,7 +19,7 @@ export type Draft = { -readonly [P in keyof T]?: T[P] } */ export interface MessageValue< Data = unknown, - MainWorker extends ClusterWorker | MessagePort | unknown = unknown + MainWorker extends ClusterWorker | MessagePort = ClusterWorker | MessagePort > extends Task { /** * Kill code. @@ -40,18 +40,51 @@ export interface MessageValue< } /** - * Worker function that can be executed types. + * Worker synchronous function that can be executed. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. */ export type WorkerSyncFunction = ( data?: Data ) => Response + +/** + * Worker asynchronous function that can be executed. + * This function must return a promise. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. + */ export type WorkerAsyncFunction = ( data?: Data ) => Promise + +/** + * Worker function that can be executed. + * This function can be synchronous or asynchronous. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. + */ export type WorkerFunction = | WorkerSyncFunction | WorkerAsyncFunction +/** + * Worker functions that can be executed. + * This object can contain synchronous or asynchronous functions. + * The key is the name of the function. + * The value is the function itself. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. + */ +export type TaskFunctions = Record< +string, +WorkerFunction +> + /** * An object holding the execution response promise resolve/reject callbacks. *