request method
Future<TransportMessage>
request(
- String subject,
- Uint8List data, {
- Map<
String, String> ? arguments, - String? originId,
- Duration? timeout,
override
Sends a request and waits for the first response.
Throws TransportServerUnavailableException when the connection is not
established and TimeoutException when no response arrives within
timeout. A null timeout waits until a response arrives.
Implementation
@override
Future<TransportMessage> request(
String subject,
Uint8List data, {
Map<String, String>? arguments,
String? originId,
Duration? timeout,
}) async {
if (!isConnected) {
throw TransportServerUnavailableException(subject);
}
final replyTo = '_INBOX.${_nextInbox++}';
requests.add(
FakeTransportRequest(subject, data, arguments, originId, replyTo),
);
final completer = Completer<TransportMessage>();
final subscription = subscribe(replyTo, (message) {
if (!completer.isCompleted) completer.complete(message);
});
try {
final response = completer.future;
return timeout == null ? await response : await response.timeout(timeout);
} finally {
await subscription.cancel();
}
}