export class ParallelCoordinator {
    createRunner;
    constructor(createRunner) {
        this.createRunner = createRunner;
    }
    async runModules(context, modules) {
        const tasks = modules.map((module) => ({
            id: module.id,
            label: module.label,
            parallelizable: true,
            execute: () => context.processModule(module),
        }));
        const runner = this.createRunner();
        const batch = await runner.execute(tasks);
        const reports = [];
        for (const result of batch.results) {
            const module = modules.find((m) => m.id === result.taskId);
            let report;
            if (result.result) {
                report = result.result;
            }
            else {
                report = {
                    id: module?.id ?? result.taskId,
                    label: module?.label ?? result.taskId,
                    scope: module?.scope ?? [],
                    steps: [],
                    status: result.status === 'completed' ? 'completed' : 'failed',
                };
            }
            if (result.status !== 'completed') {
                report.status = 'failed';
            }
            reports.push(report);
            if (result.status === 'failed' && !context.continueOnFailure) {
                break;
            }
        }
        return reports;
    }
}
//# sourceMappingURL=parallelCoordinator.js.map