24 lines
866 B
Dart
24 lines
866 B
Dart
import '../session/server_session.dart';
|
|
|
|
/// Probe only the selected profile's explicit aliases, with a bounded wait.
|
|
/// Never send a mutation or discover/switch logical servers.
|
|
Future<({Uri endpoint, SessionState state})> probeServerAddresses(
|
|
List<Uri> addresses, {
|
|
required Future<SessionState> Function(Uri) check,
|
|
required bool Function() isCurrent,
|
|
}) async {
|
|
if (addresses.isEmpty) throw ArgumentError('No server addresses to probe.');
|
|
for (final endpoint in addresses) {
|
|
if (!isCurrent()) break;
|
|
final state = await check(endpoint).timeout(
|
|
const Duration(seconds: 5),
|
|
onTimeout: () => SessionState.unreachable,
|
|
);
|
|
if (!isCurrent()) break;
|
|
if (state != SessionState.unreachable) {
|
|
return (endpoint: endpoint, state: state);
|
|
}
|
|
}
|
|
return (endpoint: addresses.first, state: SessionState.unreachable);
|
|
}
|