replaceCandidates method
Replaces the candidates — an endpoint the user moved, such as the CLI server's port — and closes the old ones. The gate is shut until the next initialize or retry selects among the new candidates; a session still on an old transport restarts on the next run's.
Implementation
Future<void> replaceCandidates(
List<AgentSdkServerTransport> candidates,
) async {
final old = _candidates;
_candidates = candidates;
_active = null;
_unavailableReason = null;
_unavailableKind = null;
_installable = null;
for (final candidate in old) {
try {
await candidate.close();
} on Object {
// Best-effort, as in [dispose]: the old endpoint may already be gone,
// which is usually why it is being replaced.
}
}
}