- private checkAndEmitBusy (): void {
- if (this.opts.enableEvents === true && this.busy === true) {
- this.emitter?.emit('busy')
- }
- }
-
- /**
- * Increases the number of tasks that the given worker has applied.
- *
- * @param worker Worker which running tasks is increased.
- */
- private increaseWorkerRunningTasks (worker: Worker): void {
- this.stepWorkerRunningTasks(worker, 1)
- }
-
- /**
- * Decreases the number of tasks that the given worker has applied.
- *
- * @param worker Worker which running tasks is decreased.
- */
- private decreaseWorkerRunningTasks (worker: Worker): void {
- this.stepWorkerRunningTasks(worker, -1)
- }
-
- /**
- * Steps the number of tasks that the given worker has applied.
- *
- * @param worker Worker which running tasks are stepped.
- * @param step Number of running tasks step.
- */
- private stepWorkerRunningTasks (worker: Worker, step: number): void {
- if (this.checkWorkerTasksUsage(worker) === true) {
- const tasksUsage = this.workersTasksUsage.get(worker) as TasksUsage
- tasksUsage.running = tasksUsage.running + step
- this.workersTasksUsage.set(worker, tasksUsage)
- }
+ private async internalExecute (
+ workerKey: number,
+ worker: Worker,
+ messageId: string
+ ): Promise<Response> {
+ this.beforePromiseResponseHook(workerKey)
+ return await new Promise<Response>((resolve, reject) => {
+ this.promiseResponseMap.set(messageId, { resolve, reject, worker })
+ })