code: function distributeTask(socket) {
    socket.taskIndexArray = [];
    for (let i = 0; i < socket.workers; i++){
      if (dethread.taskQueue.index < dethread.taskQueue.length) {
        socket.taskIndexArray.push(dethread.taskQueue.index);
        socket.emit('startTask', dethread.taskQueue.getTask());
        dethread.taskCompletionIndex++;
      } else if (dethread.failedTasks.length) {
        const failedTaskIndex = dethread.failedTasks.pop();
        socket.taskIndexArray.push(failedTaskIndex);
        socket.emit('startTask', dethread.taskQueue.getTask(failedTaskIndex));
        dethread.taskCompletionIndex++;
      } else if (!socket.taskIndexArray.length) {
        dethread.socketPool.push(socket);
      }
    }
  }
docs: dethread local variables and functions: handles socket communication and task distribution logic