@nsshunt/stsrunnerframework 1.0.199 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1059 -1
  2. package/dist/stsrunnerframework.mjs +8263 -4103
  3. package/dist/stsrunnerframework.mjs.map +1 -1
  4. package/dist/stsrunnerframework.umd.js +8288 -4117
  5. package/dist/stsrunnerframework.umd.js.map +1 -1
  6. package/package.json +4 -4
  7. package/types/abstractRunnerExecutionWorker.d.ts +194 -0
  8. package/types/abstractRunnerExecutionWorker.d.ts.map +1 -0
  9. package/types/archiveManager.d.ts +172 -0
  10. package/types/archiveManager.d.ts.map +1 -0
  11. package/types/asyncRunnerInstanceManager.d.ts +108 -0
  12. package/types/asyncRunnerInstanceManager.d.ts.map +1 -0
  13. package/types/commonTypes.d.ts +115 -35
  14. package/types/commonTypes.d.ts.map +1 -1
  15. package/types/index.d.ts +1 -1
  16. package/types/index.d.ts.map +1 -1
  17. package/types/messageBroker.d.ts +324 -0
  18. package/types/messageBroker.d.ts.map +1 -0
  19. package/types/runnerInstance.d.ts +245 -0
  20. package/types/runnerInstance.d.ts.map +1 -0
  21. package/types/runnerLifecycleManager.d.ts +210 -0
  22. package/types/runnerLifecycleManager.d.ts.map +1 -0
  23. package/types/telemetryProcessor.d.ts +67 -0
  24. package/types/telemetryProcessor.d.ts.map +1 -1
  25. package/types/testing/mockedWorkerTestRunner01.d.ts +129 -2
  26. package/types/testing/mockedWorkerTestRunner01.d.ts.map +1 -1
  27. package/types/testing/testCase01.d.ts +222 -2
  28. package/types/testing/testCase01.d.ts.map +1 -1
  29. package/types/testing/testCase02.d.ts +206 -2
  30. package/types/testing/testCase02.d.ts.map +1 -1
  31. package/types/testing/wmwokerProcess.test.d.ts +1 -0
  32. package/types/testing/wmwokerProcess2.test.d.ts +1 -0
  33. package/types/workerCommandCoordinator.d.ts +152 -0
  34. package/types/workerCommandCoordinator.d.ts.map +1 -0
  35. package/types/workerInstance.d.ts +340 -16
  36. package/types/workerInstance.d.ts.map +1 -1
  37. package/types/workerInstanceMannager.d.ts +170 -0
  38. package/types/workerInstanceMannager.d.ts.map +1 -0
  39. package/types/workerManager.d.ts +335 -24
  40. package/types/workerManager.d.ts.map +1 -1
  41. package/types/workerRegistry.d.ts +251 -0
  42. package/types/workerRegistry.d.ts.map +1 -0
  43. package/types/workerStateSynchroniser.d.ts +161 -0
  44. package/types/workerStateSynchroniser.d.ts.map +1 -0
@@ -1,20 +1,344 @@
1
- import { MessagePort } from 'worker_threads';
2
- import { IRunnerInstance, IRunner, ITestRunnerTelemetryPayload, IWorkerOptions } from './commonTypes';
3
- import { ISTSLogger } from '@nsshunt/stsutils';
4
- export interface IRunnerEx2RunState {
5
- runnerInstance: IRunnerInstance;
6
- runner: IRunner;
7
- archived: boolean;
1
+
2
+ /**
3
+ * WorkerInstance
4
+ * ----------------
5
+ * Concrete runtime implementation of {@link IWorkerEx}.
6
+ *
7
+ * A WorkerInstance represents a single worker process/thread plus the collection
8
+ * of runner instances hosted inside that worker.
9
+ *
10
+ * Responsibilities:
11
+ * - Own the in-memory collection of runner instances for this worker
12
+ * - Dispatch commands to individual runners via the message broker
13
+ * - Dispatch bulk commands to all runners in this worker
14
+ * - Create and register new runners in this worker
15
+ * - Expose serialisable worker models (`toJSON`, `toWorker`, `toWorkerCore`)
16
+ * - Maintain worker-level event subscriptions
17
+ * - Coordinate worker termination and registry cleanup
18
+ */
19
+ import { IExecuteRunnerActionResult, IRunnerEvent, IRunnerEx, IRunnerOptions, IRunnerState, IWorker, IWorkerCore, IWorkerEx, IWorkerFactory, IWorkerOptions, IWorkerEvent } from './commonTypes';
20
+ import { WorkerRegistry } from './workerRegistry';
21
+ import { STSMessageBroker } from './messageBroker';
22
+ import { AsyncRunnerInstanceManager } from './asyncRunnerInstanceManager';
23
+ import type { Worker as NodeWorker, MessagePort as NodeMessagePort } from 'node:worker_threads';
24
+ /**
25
+ * Runtime worker type supporting both browser and Node.js workers.
26
+ */
27
+ export type RuntimeWorker = Worker | NodeWorker;
28
+ /**
29
+ * Runtime message port type supporting both browser and Node.js message ports.
30
+ */
31
+ export type RuntimeMessagePort = MessagePort | NodeMessagePort;
32
+ /**
33
+ * Constructor options required to create a {@link WorkerInstance}.
34
+ *
35
+ * Notes:
36
+ * - `workerManagerId` identifies the owning worker manager instance.
37
+ * - `workerOptions` contains the runtime configuration for the worker itself.
38
+ * - `messagePort` is the communication port already allocated for this worker.
39
+ * - `workerFactory` is responsible for creating the underlying actual worker thread/process.
40
+ * - `messageBroker` is used for request/response message dispatch to the worker.
41
+ * - `workerRegistry` is used for central registry cleanup during termination.
42
+ * - `asyncRunnerInstanceManager` is used to construct runner instances for this worker.
43
+ * - `logger` is intentionally minimal and only requires debug/error methods.
44
+ */
45
+ export interface IWorkerInstanceOptions {
46
+ /** Id of the owning worker manager. */
47
+ workerManagerId: string;
48
+ /** Worker-specific runtime configuration. */
49
+ workerOptions: IWorkerOptions;
50
+ /** Message port used by this worker for brokered communications. */
51
+ messagePort: RuntimeMessagePort;
52
+ /** Factory used to construct the underlying worker implementation. */
53
+ workerFactory: IWorkerFactory;
54
+ /** Broker used to send commands and correlate responses for this worker. */
55
+ messageBroker: STSMessageBroker;
56
+ /** Shared registry containing all live worker instances. */
57
+ workerRegistry: WorkerRegistry;
58
+ /** Factory/manager used to create runner instances for this worker. */
59
+ asyncRunnerInstanceManager: AsyncRunnerInstanceManager;
60
+ /** Logger abstraction used by this class. */
61
+ logger: {
62
+ debug: (message: any) => void;
63
+ error: (message: any) => void;
64
+ };
8
65
  }
9
- export declare abstract class WorkerInstance {
66
+ /**
67
+ * Concrete worker runtime instance.
68
+ *
69
+ * This class owns:
70
+ * - the underlying worker handle (`worker`)
71
+ * - the broker message port (`messagePort`)
72
+ * - all runner instances hosted inside this worker (`__runnersEx`)
73
+ * - worker-level event subscriptions (`workerEvents`)
74
+ * - runner-level event subscription collections (`runnersEvents`)
75
+ *
76
+ * Design notes:
77
+ * - `__runnersEx` is intentionally private to stop callers from mutating the
78
+ * runner collection directly.
79
+ * - The class delegates command dispatch to the message broker rather than
80
+ * communicating with the underlying worker directly.
81
+ * - Most public methods are thin orchestration methods over private helpers.
82
+ */
83
+ export declare class WorkerInstance implements IWorkerEx {
10
84
  #private;
11
- get logger(): ISTSLogger;
12
- constructor();
13
- GetRandomInt: (max: number) => number;
14
- PostTelemetryById: (id: string) => void;
15
- get CollectorCollectorPort(): MessagePort | null;
16
- get Options(): IWorkerOptions | null;
17
- CreateAsyncRunner: (testRunnerTelemetryPayload: ITestRunnerTelemetryPayload) => Promise<IRunnerInstance | null>;
18
- ProcessMessage: (data: any) => Promise<void>;
85
+ /** Unique identifier for this worker instance. */
86
+ id: string;
87
+ /** Id of the owning worker manager. */
88
+ workerManagerId: string;
89
+ /**
90
+ * Underlying actual worker runtime (browser worker or Node worker thread).
91
+ */
92
+ worker: RuntimeWorker;
93
+ /**
94
+ * Registered worker-level event subscriptions.
95
+ *
96
+ * Typical events may include lifecycle events emitted elsewhere in the system,
97
+ * such as `exit`, `error`, etc.
98
+ */
99
+ workerEvents: IWorkerEvent[];
100
+ /**
101
+ * Communication port used by the message broker for this worker.
102
+ */
103
+ messagePort: RuntimeMessagePort;
104
+ /** Worker runtime configuration. */
105
+ options: IWorkerOptions;
106
+ /**
107
+ * Per-runner event subscription collections, keyed by runner id.
108
+ *
109
+ * Each runner id maps to a list of subscriptions interested in events
110
+ * for that specific runner.
111
+ */
112
+ runnersEvents: Record<string, IRunnerEvent[]>;
113
+ /**
114
+ * Private in-memory map of runner runtime instances owned by this worker.
115
+ *
116
+ * Key: runner id
117
+ * Value: live runner runtime instance
118
+ */
119
+ private __runnersEx;
120
+ /**
121
+ * Construct a new live worker runtime instance.
122
+ *
123
+ * Behaviour:
124
+ * - Generates a new worker id
125
+ * - Creates the underlying concrete worker using the provided factory
126
+ * - Stores the provided message port and runtime options
127
+ * - Stores references to collaborating services
128
+ *
129
+ * @param options Dependencies and configuration required to construct the worker.
130
+ */
131
+ constructor(options: IWorkerInstanceOptions);
132
+ /**
133
+ * Add an already-created runner runtime instance into this worker's internal collection.
134
+ *
135
+ * This method only updates local in-memory state. It does not send any message
136
+ * to the underlying worker. Use {@link AddRunner} when you want the runner to be
137
+ * both created locally and pushed into the underlying worker process/thread.
138
+ *
139
+ * @param runnerEx Runner runtime instance to register under this worker.
140
+ */
141
+ AddRunnerEx(runnerEx: IRunnerEx): void;
142
+ /**
143
+ * Get a single runner runtime instance by id.
144
+ *
145
+ * @param id Runner id to look up.
146
+ * @returns The runner instance if found, otherwise `null`.
147
+ */
148
+ GetRunnerEx(id: string): IRunnerEx | null;
149
+ /**
150
+ * Get the raw internal runner map for this worker.
151
+ *
152
+ * Note:
153
+ * This returns the live in-memory map, not a defensive copy.
154
+ *
155
+ * @returns Record of runner id -> runner instance.
156
+ */
157
+ GetAllRunnersExMap(): Record<string, IRunnerEx>;
158
+ /**
159
+ * Get all runner runtime instances currently hosted by this worker.
160
+ *
161
+ * @returns Array of all runner instances.
162
+ */
163
+ GetAllRunnersEx(): IRunnerEx[];
164
+ /**
165
+ * Get runner runtime instances filtered by runner id.
166
+ *
167
+ * Behaviour:
168
+ * - If `runnerIds` is empty, all runners are returned.
169
+ * - Otherwise only matching runner ids are returned.
170
+ *
171
+ * @param runnerIds List of runner ids to include. Use `[]` to include all.
172
+ * @returns Filtered runner list.
173
+ */
174
+ GetRunnersEx(runnerIds: string[]): IRunnerEx[];
175
+ /**
176
+ * Create a new runner runtime instance, register it in this worker,
177
+ * and send an `AddRunner` command to the underlying worker.
178
+ *
179
+ * @param runnerOptions Runtime options for the new runner.
180
+ * @returns Newly created runner instance once successfully registered with the underlying worker.
181
+ */
182
+ AddRunner(runnerOptions: IRunnerOptions): Promise<IRunnerEx>;
183
+ /**
184
+ * Send a `StartRunner` command for the specified runner.
185
+ *
186
+ * @param runner Target runner.
187
+ * @returns Action result returned by the worker.
188
+ */
189
+ StartRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
190
+ /**
191
+ * Send a `StopRunner` command for the specified runner.
192
+ *
193
+ * @param runner Target runner.
194
+ * @returns Action result returned by the worker.
195
+ */
196
+ StopRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
197
+ /**
198
+ * Send a `PauseRunner` command for the specified runner.
199
+ *
200
+ * @param runner Target runner.
201
+ * @returns Action result returned by the worker.
202
+ */
203
+ PauseRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
204
+ /**
205
+ * Send a `ResumeRunner` command for the specified runner.
206
+ *
207
+ * @param runner Target runner.
208
+ * @returns Action result returned by the worker.
209
+ */
210
+ ResumeRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
211
+ /**
212
+ * Send a `TerminateRunner` command for the specified runner.
213
+ *
214
+ * @param runner Target runner.
215
+ * @returns Action result returned by the worker.
216
+ */
217
+ TerminateRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
218
+ /**
219
+ * Send a `ResetRunner` command for the specified runner.
220
+ *
221
+ * @param runner Target runner.
222
+ * @returns Action result returned by the worker.
223
+ */
224
+ ResetRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
225
+ /**
226
+ * Send an `ExecuteRunner` command for the specified runner.
227
+ *
228
+ * @param runner Target runner.
229
+ * @returns Action result returned by the worker.
230
+ */
231
+ ExecuteRunner(runner: IRunnerEx): Promise<IExecuteRunnerActionResult>;
232
+ /**
233
+ * Send an `UpdateRunner` command for the specified runner.
234
+ *
235
+ * @param runner Target runner.
236
+ * @param runnerOptions Partial runner option updates to apply.
237
+ * @returns Action result returned by the worker.
238
+ */
239
+ UpdateRunner(runner: IRunnerEx, runnerOptions: Partial<IRunnerOptions>): Promise<IExecuteRunnerActionResult>;
240
+ /**
241
+ * Send `Start` to all runners in this worker.
242
+ *
243
+ * @returns Array of per-runner action results.
244
+ */
245
+ Start(): Promise<IExecuteRunnerActionResult[]>;
246
+ /**
247
+ * Send `Stop` to all runners in this worker.
248
+ *
249
+ * @returns Array of per-runner action results.
250
+ */
251
+ Stop(): Promise<IExecuteRunnerActionResult[]>;
252
+ /**
253
+ * Send `Pause` to all runners in this worker.
254
+ *
255
+ * @returns Array of per-runner action results.
256
+ */
257
+ Pause(): Promise<IExecuteRunnerActionResult[]>;
258
+ /**
259
+ * Send `Resume` to all runners in this worker.
260
+ *
261
+ * @returns Array of per-runner action results.
262
+ */
263
+ Resume(): Promise<IExecuteRunnerActionResult[]>;
264
+ /**
265
+ * Send `Reset` to all runners in this worker.
266
+ *
267
+ * @returns Array of per-runner action results.
268
+ */
269
+ Reset(): Promise<IExecuteRunnerActionResult[]>;
270
+ /**
271
+ * Send `Execute` to all runners in this worker.
272
+ *
273
+ * @returns Array of per-runner action results.
274
+ */
275
+ Execute(): Promise<IExecuteRunnerActionResult[]>;
276
+ /**
277
+ * Send `Update` to all runners in this worker.
278
+ *
279
+ * @param runnerOptions Partial runner option updates to apply to all runners.
280
+ * @returns Array of per-runner action results.
281
+ */
282
+ Update(runnerOptions: Partial<IRunnerOptions>): Promise<IExecuteRunnerActionResult[]>;
283
+ /**
284
+ * Terminate all runners in this worker and then terminate the underlying worker itself.
285
+ *
286
+ * Behaviour:
287
+ * - Calls `Terminate()` on all runner instances first
288
+ * - Waits for those promises via `Promise.all`
289
+ * - Schedules actual worker termination 500ms later
290
+ * - Removes the worker from the central registry after terminating the worker
291
+ *
292
+ * Notes:
293
+ * - This method intentionally handles worker-level shutdown separately rather than
294
+ * using {@link #invokeCommand} because worker termination involves additional
295
+ * cleanup beyond runner termination.
296
+ * - The 500ms timeout is a grace period before terminating the underlying worker.
297
+ *
298
+ * @returns Array of per-runner action results, or `[]` if termination setup fails.
299
+ */
300
+ Terminate(): Promise<IExecuteRunnerActionResult[]>;
301
+ /**
302
+ * Register a worker-level event subscription.
303
+ *
304
+ * This supports a fluent style:
305
+ * `worker.on('exit', cb).on('error', cb2)`
306
+ *
307
+ * @param eventName Name of the event to subscribe to.
308
+ * @param cb Callback to invoke when the event is emitted.
309
+ * @returns The current worker instance for chaining.
310
+ */
311
+ on(eventName: string, cb: (args?: any) => void): IWorkerEx;
312
+ /**
313
+ * Convert this live worker runtime instance into a serialisable worker model.
314
+ *
315
+ * Behaviour:
316
+ * - Copies worker metadata
317
+ * - Serialises all live runners via `runnerEx.toJSON()`
318
+ *
319
+ * @returns Full serialisable worker model.
320
+ */
321
+ toJSON(): IWorker;
322
+ /**
323
+ * Alias for {@link toJSON}.
324
+ *
325
+ * @returns Full serialisable worker model.
326
+ */
327
+ toWorker(): IWorker;
328
+ /**
329
+ * Convert this worker into a reduced/core representation.
330
+ *
331
+ * Behaviour:
332
+ * - Includes only the worker id plus filtered runner core models
333
+ * - If `states` is:
334
+ * - `undefined`: includes all runners
335
+ * - `[]`: includes all runners
336
+ * - populated: includes only runners whose state matches one of the provided states
337
+ *
338
+ * @param states Optional runner state filter.
339
+ * @returns Core worker model containing core runner representations.
340
+ * @throws Re-throws any error after logging.
341
+ */
342
+ toWorkerCore(states?: IRunnerState[]): IWorkerCore;
19
343
  }
20
344
  //# sourceMappingURL=workerInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workerInstance.d.ts","sourceRoot":"","sources":["../src/workerInstance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAuE,eAAe,EAC7D,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAGnF,MAAM,eAAe,CAAA;AAMtB,OAAO,EAAE,UAAU,EAAwB,MAAM,mBAAmB,CAAC;AAErE,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,eAAe,CAAA;IAC/B,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;CACpB;AAED,8BAAsB,cAAc;;IAOhC,IAAI,MAAM,IAAI,UAAU,CAEvB;;IA4FD,YAAY,GAAI,KAAK,MAAM,YAEzB;IAEF,iBAAiB,GAAI,IAAI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IAAI,OAAO,CAAC,0BAA0B,EAAE,CAAC;IA0BxD;;;;;;;;;OASG;IACH,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,SAAS;IAQ1D;;;;;;;;OAQG;IACH,MAAM,IAAI,OAAO;IAejB;;;;OAIG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,GAAG,WAAW;CAgIrD"}
@@ -0,0 +1,170 @@
1
+
2
+ /**
3
+ * WorkerInstanceManager
4
+ * =====================
5
+ *
6
+ * Factory and lifecycle helper responsible for:
7
+ *
8
+ * - constructing manager-side worker runtime objects (`IWorkerEx`)
9
+ * - wiring shared dependencies into those worker instances
10
+ * - attaching low-level system/runtime event handlers to the underlying actual worker
11
+ * - translating native worker events into higher-level worker events
12
+ * - removing failed/exited workers from the shared registry
13
+ *
14
+ * Role in the architecture
15
+ * ------------------------
16
+ * This class lives on the **manager/controller side** of the system.
17
+ *
18
+ * It should not be confused with:
19
+ *
20
+ * - the actual browser Web Worker / Node worker thread runtime, or
21
+ * - the abstract worker-runtime execution host that runs inside the worker
22
+ *
23
+ * Instead, this class is responsible for creating and configuring the
24
+ * manager-side `IWorkerEx` object that represents a live worker to the rest
25
+ * of the coordination layer.
26
+ *
27
+ * Typical responsibilities in practice
28
+ * ------------------------------------
29
+ * 1. Create a new manager-side worker object using the configured factory
30
+ * 2. Inject shared collaborators such as:
31
+ * - message broker
32
+ * - worker registry
33
+ * - async runner instance manager
34
+ * 3. Attach low-level native worker runtime event listeners:
35
+ * - Node.js: `exit`, `error`
36
+ * - Browser: `onerror`, `onmessageerror`
37
+ * 4. Forward those low-level events into higher-level worker events
38
+ * 5. Remove failed/exited workers from the shared registry when appropriate
39
+ */
40
+ import { IWorkerEx, IWorkerFactory, IWorkerOptions } from './commonTypes';
41
+ import { ISTSLogger } from '@nsshunt/stsutils';
42
+ import { STSMessageBroker } from './messageBroker';
43
+ import { AsyncRunnerInstanceManager } from './asyncRunnerInstanceManager';
44
+ import { WorkerRegistry } from './workerRegistry';
45
+ /**
46
+ * Constructor options for {@link WorkerInstanceManager}.
47
+ */
48
+ export interface IWorkerInstanceManagerOptions {
49
+ /**
50
+ * Id of the top-level worker manager that owns all workers created through this manager.
51
+ */
52
+ workerManagerId: string;
53
+ /**
54
+ * Logger used for diagnostics and error reporting.
55
+ */
56
+ logger: ISTSLogger;
57
+ /**
58
+ * Shared message broker used by created worker instances to communicate with their
59
+ * underlying actual worker runtime.
60
+ */
61
+ messageBroker: STSMessageBroker;
62
+ /**
63
+ * Shared live worker registry.
64
+ *
65
+ * Used when system events require worker removal/cleanup.
66
+ */
67
+ workerRegistry: WorkerRegistry;
68
+ /**
69
+ * Shared async runner instance manager used by worker instances when creating runners.
70
+ */
71
+ asyncRunnerInstanceManager: AsyncRunnerInstanceManager;
72
+ }
73
+ /**
74
+ * Manager-side factory/helper for worker instances.
75
+ *
76
+ * This class creates concrete manager-side {@link IWorkerEx} objects and attaches
77
+ * platform-specific system event listeners to the underlying worker runtime.
78
+ */
79
+ export declare class WorkerInstanceManager {
80
+ /**
81
+ * Immutable runtime configuration and dependencies for this manager.
82
+ */
83
+ private readonly options;
84
+ /**
85
+ * Construct a new worker instance manager.
86
+ *
87
+ * @param options Shared collaborators required to create and manage worker instances.
88
+ */
89
+ constructor(options: IWorkerInstanceManagerOptions);
90
+ /**
91
+ * Create a new manager-side worker instance.
92
+ *
93
+ * Behaviour:
94
+ * - constructs a new concrete {@link WorkerInstance}
95
+ * - injects all shared collaborators required by that worker instance
96
+ * - returns the created manager-side worker object
97
+ *
98
+ * Notes:
99
+ * - This does not automatically register the worker in the registry
100
+ * - This does not automatically attach system/runtime event handlers
101
+ * - Those are handled separately by the caller
102
+ *
103
+ * Dependencies injected into the worker include:
104
+ * - worker manager id
105
+ * - worker-specific options
106
+ * - message port
107
+ * - worker factory
108
+ * - message broker
109
+ * - worker registry
110
+ * - async runner instance manager
111
+ * - logger
112
+ *
113
+ * @param workerOptions Worker-specific runtime configuration.
114
+ * @param port Message port used for brokered worker communication.
115
+ * @param workerFactory Factory used to create the underlying actual worker runtime.
116
+ * @returns Newly created manager-side worker instance.
117
+ */
118
+ CreateWorkerInstance: (workerOptions: IWorkerOptions, port: any, workerFactory: IWorkerFactory) => IWorkerEx;
119
+ /**
120
+ * Attach low-level system/runtime event handlers to the underlying actual worker.
121
+ *
122
+ * Environment-specific behaviour:
123
+ *
124
+ * Node.js worker thread:
125
+ * - attaches `exit`
126
+ * - attaches `error`
127
+ *
128
+ * Browser Web Worker:
129
+ * - attaches `onerror`
130
+ * - attaches `onmessageerror`
131
+ *
132
+ * Event handling behaviour
133
+ * ------------------------
134
+ * - Logs the low-level worker event
135
+ * - Emits a higher-level worker event to any subscribers on `workerEx.workerEvents`
136
+ * - Removes the worker from the shared registry when appropriate
137
+ *
138
+ * Registry removal behaviour:
139
+ * - Node `exit` -> deletes worker from registry
140
+ * - Browser `onerror` -> deletes worker from registry
141
+ * - Node `error` does not immediately delete the worker
142
+ * - Browser `onmessageerror` does not immediately delete the worker
143
+ *
144
+ * Notes:
145
+ * - This method should typically be called after creating the worker instance
146
+ * and before the worker is considered fully live
147
+ * - For mocked workers or other special worker implementations, callers may
148
+ * choose not to attach these runtime handlers
149
+ *
150
+ * @param stsWorkerEx Manager-side worker instance whose underlying actual worker should be monitored.
151
+ */
152
+ SetupWorkerSystemEvents: (stsWorkerEx: IWorkerEx) => void;
153
+ /**
154
+ * Emit a higher-level worker event to any registered worker event subscribers.
155
+ *
156
+ * Behaviour:
157
+ * - iterates the worker's registered `workerEvents`
158
+ * - matches handlers whose `eventName` equals the supplied event name
159
+ * - invokes each matching callback with the live worker instance
160
+ *
161
+ * This method is used to translate low-level native worker/runtime events into
162
+ * the higher-level event model used by the rest of the framework.
163
+ *
164
+ * @param eventName Name of the worker event to emit.
165
+ * @param workerEx Live manager-side worker instance associated with the event.
166
+ * @throws Re-throws unexpected errors after logging.
167
+ */
168
+ private _EmitWorkerEvent;
169
+ }
170
+ //# sourceMappingURL=workerInstanceMannager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerInstanceMannager.d.ts","sourceRoot":"","sources":["../src/workerInstanceMannager.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC1C;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IAEnB;;;OAGG;IACH,aAAa,EAAE,gBAAgB,CAAC;IAEhC;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAE/B;;OAEG;IACH,0BAA0B,EAAE,0BAA0B,CAAC;CAC1D;AAED;;;;;GAKG;AACH,qBAAa,qBAAqB;IAC9B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IAExD;;;;OAIG;gBACS,OAAO,EAAE,6BAA6B;IAIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,oBAAoB,GAChB,eAAe,cAAc,EAC7B,MAAM,GAAG,EACT,eAAe,cAAc,KAC9B,SAAS,CAWV;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,uBAAuB,GAAI,aAAa,SAAS,UAqF/C;IAEF;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,gBAAgB,CAWtB;CACL"}