+ // 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
+ )
+ } else if (isPlainObject(taskFunctions)) {
+ let firstEntry = true
+ for (const [name, fn] of Object.entries(taskFunctions)) {
+ checkValidTaskFunctionEntry<Data, Response>(name, fn)
+ const boundFn = fn.bind(this)
+ if (firstEntry) {
+ this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
+ firstEntry = false
+ }
+ this.taskFunctions.set(name, boundFn)
+ }
+ if (firstEntry) {
+ throw new Error('taskFunctions parameter object is empty')
+ }
+ } else {
+ throw new TypeError(
+ 'taskFunctions parameter is not a function or a plain object'