request method
Registers key as awaiting a response, runs send, then waits.
Implementation
Future<IsoMsg?> request(String key, Future<void> Function() send, Duration timeout) async {
if (_pending.containsKey(key)) throw StateError("duplicate in-flight message key $key");
final Completer<IsoMsg> completer = Completer<IsoMsg>();
_pending[key] = completer;
_sent++;
try {
await send();
final IsoMsg response = await completer.future.timeout(timeout);
_received++;
return response;
} on TimeoutException {
_expired++;
return null;
} finally {
_pending.remove(key);
}
}