getRemainingResults method
Wait for remaining tools and return their results.
Implementation
Stream<MessageUpdate> getRemainingResults() async* {
if (_discarded) return;
while (_tools.any((t) => t.status != ToolStatus.yielded)) {
_processQueue();
for (final result in getCompletedResults()) {
yield result;
}
// Wait for any executing tool to complete or progress to be available
if (_tools.any((t) => t.status == ToolStatus.executing)) {
final executingPromises = _tools
.where((t) => t.status == ToolStatus.executing && t.promise != null)
.map((t) => t.promise!)
.toList();
_progressAvailableCompleter = Completer<void>();
if (executingPromises.isNotEmpty) {
await Future.any([
...executingPromises,
_progressAvailableCompleter!.future,
]);
}
}
}
for (final result in getCompletedResults()) {
yield result;
}
}