- this.lastTaskTimestamp = performance.now()
- this.aliveInterval = setInterval(
- this.checkAlive.bind(this),
- (this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2
+ // Should be once() but Node.js on windows has a bug that prevents it from working
+ this.getMainWorker().on('message', this.handleReadyMessage.bind(this))
+ }
+ }
+
+ private checkWorkerOptions (opts: WorkerOptions): void {
+ checkValidWorkerOptions(opts)
+ this.opts = { ...DEFAULT_WORKER_OPTIONS, ...opts }
+ }
+
+ /**
+ * Checks if the `taskFunctions` parameter is passed to the constructor and valid.
+ *
+ * @param taskFunctions - The task function(s) parameter that should be checked.
+ */
+ private checkTaskFunctions (
+ taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>
+ ): void {
+ if (taskFunctions == null) {
+ throw new Error('taskFunctions parameter is mandatory')
+ }
+ this.taskFunctions = new Map<string, TaskFunction<Data, Response>>()
+ if (typeof taskFunctions === 'function') {
+ const boundFn = taskFunctions.bind(this)
+ this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
+ this.taskFunctions.set(
+ typeof taskFunctions.name === 'string' &&
+ taskFunctions.name.trim().length > 0
+ ? taskFunctions.name
+ : 'fn1',
+ boundFn