bridgeHandshake function
Future<({String? error, int? protocol})>
bridgeHandshake(
- String path, {
- ProcessRunner run = boundedRun,
Asks the bridge for its protocol number; null with error when it cannot say.
Implementation
Future<({int? protocol, String? error})> bridgeHandshake(String path, {ProcessRunner run = boundedRun}) async {
try {
final res = await runCapped(
run,
path,
['version'],
timeout: const Duration(seconds: 5),
phase: 'bridge version',
);
final m = RegExp(r'glint-iossim (\d+)').firstMatch('${res.stdout}');
if (res.exitCode == 0 && m != null) {
return (protocol: int.parse(m.group(1)!), error: null);
}
return (protocol: null, error: 'the bridge predates the version handshake');
} on ProcessException catch (e) {
return (protocol: null, error: 'could not run the bridge: ${e.message}');
} on TimeoutException {
return (protocol: null, error: 'the bridge did not answer `version` in 5s');
} on ProcessTimeoutError {
return (protocol: null, error: 'the bridge did not answer `version` in 5s');
}
}