Помогите разобраться, почему промисы не резолвятся? Код просто встает в первом цикле.
Мне кажется, я что-то не уловил базовое в промисах, так как изучаю JS не так давно.
Суть задачи: таскменеджер, в котором свободные роботы выполняют задачи, пока задачи не кончатся в очереди.
class Robot {
    constructor() {
        this._isFree = true;
        this._successCount = 0;
        this._failedCount = 0;
        this._tasks = [];
        this._timeSpent = 0;
    }
    get isFree() {
        return this._isFree;
    }
    doTask(task) {
        this._tasks.push(task.id);
        this._isFree = false;
        const startTime = Date.now();
        const promise = task.job();
        promise
            .then(() => this._successCount++)
            .catch(() => this._failedCount++)
            .finally(() => {
                this._timeSpent += Date.now - startTime;
                this._isFree = true;
            });
    }
    getReport() {
        return {
            successCount: this._successCount,
            failedCount: this._failedCount,
            tasks: this._tasks.slice(),
            timeSpent: this._timeSpen,
        };
    }
}
class TaskManager {
    constructor(N) {
        this._tasksQueue = [];
        this._robots = [];
        for (let i = 0; i < N; i++)
            this._robots.push(new Robot());
    }
    addToQueue(task) {
        this._tasksQueue.push(task);
    }
    run() {
        this._tasksQueue.sort((aTask, bTask) => aTask.priority - bTask.priority);
        while (this._tasksQueue.length) {
            const robot = this._robots.find(robot => robot.isFree);
            if (robot)
                robot.doTask(this._tasksQueue.pop());
        }
        while (this._robots.some(robot => !robot.isFree)) { }
        return new Promise((resolve) => {
            resolve(this._robots.reduce((report, robot) => {
                report.push(robot.getReport());
                return report;
            }, []));
        });
    }
}