Commit | Line | Data |
---|---|---|
4d7227e6 | 1 | import { WorkerData, WorkerOptions } from '../types/Worker'; |
4bfd80fa | 2 | |
3fa0f0ed | 3 | import WorkerConstants from './WorkerConstants'; |
7dde0b73 | 4 | |
c3ee95af | 5 | export default abstract class WorkerAbstract<T extends WorkerData> { |
322c9192 | 6 | protected readonly workerScript: string; |
4d7227e6 | 7 | protected readonly workerOptions: WorkerOptions; |
f2bf9948 JB |
8 | public abstract readonly size: number; |
9 | public abstract readonly maxElementsPerWorker: number | null; | |
6af9012e | 10 | |
7dde0b73 | 11 | /** |
e71cccf3 | 12 | * `WorkerAbstract` constructor. |
7dde0b73 | 13 | * |
81797102 | 14 | * @param workerScript |
4d7227e6 | 15 | * @param workerOptions |
7dde0b73 | 16 | */ |
e7aeea18 JB |
17 | constructor( |
18 | workerScript: string, | |
19 | workerOptions: WorkerOptions = { | |
3fa0f0ed JB |
20 | workerStartDelay: WorkerConstants.DEFAULT_WORKER_START_DELAY, |
21 | elementStartDelay: WorkerConstants.DEFAULT_ELEMENT_START_DELAY, | |
22 | poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE, | |
23 | poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE, | |
24 | elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER, | |
e7aeea18 JB |
25 | poolOptions: {}, |
26 | messageHandler: () => { | |
27 | /* This is intentional */ | |
28 | }, | |
29 | } | |
30 | ) { | |
ad2f27c3 | 31 | this.workerScript = workerScript; |
4d7227e6 | 32 | this.workerOptions = workerOptions; |
7dde0b73 JB |
33 | } |
34 | ||
418106c8 | 35 | public abstract start(): Promise<void>; |
ded13d97 | 36 | public abstract stop(): Promise<void>; |
c3ee95af | 37 | public abstract addElement(elementData: T): Promise<void>; |
7dde0b73 | 38 | } |