import { SerializableError } from '../../models/SerializableError.js';
import { sleep } from '../../lib/timers/Timers.js';
import { ProjectRunner } from './ProjectRunner.js';
import { State } from './enums.js';
/**
 * Project runner that runs the requests in the project one-by-one.
 */
export class ProjectSerialRunner extends ProjectRunner {
    /**
     * Executes the requests in the project.
     */
    async execute() {
        const { root } = this;
        if (!root) {
            throw new SerializableError(`The project runner is not configured.`, 'ECONFIGURE');
        }
        this._state = State.Running;
        this.startTime = Date.now();
        while (this.remaining > 0) {
            this.remaining--;
            await this.executeIteration();
            this.index++;
            if (this.remaining && this.options?.iterationDelay) {
                this.emit('before-sleep');
                await sleep(this.options.iterationDelay);
                this.emit('after-sleep');
            }
            else {
                await sleep(0);
            }
        }
        this._state = State.Idle;
        this.endTime = Date.now();
        return this.createReport();
    }
}
//# sourceMappingURL=ProjectSerialRunner.js.map