startWorkers method
Runs the jobs
in parallel, with at most numWorkers jobs running
simultaneously.
If the supplied job is a WorkerJobGroup, then the jobs in the task group will be run so that the tasks are executed in order (but still in parallel with other jobs).
Returns the the jobs in a Stream as they are completed.
Implementation
Stream<WorkerJob> startWorkers(Iterable<DependentJob> jobs) async* {
assert(_inProgressJobs == 0);
_failedJobs.clear();
_completedJobs.clear();
if (jobs.isEmpty) {
return;
}
for (final DependentJob job in jobs) {
job.addToQueue(_pendingJobs);
}
_verifyDependencies();
final List<Stream<WorkerJob>> streams = <Stream<WorkerJob>>[];
for (int i = 0; i < numWorkers; ++i) {
if (_pendingJobs.isEmpty) {
break;
}
streams.add(_startWorker());
}
await for (final WorkerJob job in StreamGroup.merge<WorkerJob>(streams)) {
yield job;
}
assert(_pendingJobs.isEmpty);
assert(_inProgressJobs == 0);
_printReportIfNeeded();
return;
}