- const res = new Promise<Response>((resolve, reject) => {
- this.promiseResponseMap.set(submittedTask.id as string, {
+ }
+
+ /** @inheritDoc */
+ public async execute (
+ data?: Data,
+ name?: string,
+ transferList?: TransferListItem[]
+ ): Promise<Response> {
+ return await new Promise<Response>((resolve, reject) => {
+ if (name != null && typeof name !== 'string') {
+ reject(new TypeError('name argument must be a string'))
+ }
+ if (
+ name != null &&
+ typeof name === 'string' &&
+ name.trim().length === 0
+ ) {
+ reject(new TypeError('name argument must not be an empty string'))
+ }
+ if (
+ name != null &&
+ this.taskFunctions != null &&
+ !this.taskFunctions.includes(name)
+ ) {
+ reject(
+ new Error(`Task function '${name}' is not registered in the pool`)
+ )
+ }
+ if (transferList != null && !Array.isArray(transferList)) {
+ reject(new TypeError('transferList argument must be an array'))
+ }
+ const timestamp = performance.now()
+ const workerNodeKey = this.chooseWorkerNode()
+ const task: Task<Data> = {
+ name: name ?? DEFAULT_TASK_NAME,
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+ data: data ?? ({} as Data),
+ transferList,
+ timestamp,
+ workerId: this.getWorkerInfo(workerNodeKey).id as number,
+ taskId: randomUUID()
+ }
+ this.promiseResponseMap.set(task.taskId as string, {