request<T> method
Future
request<T>(
- T data, {
- List<
String> ? paths, - String? separator,
- Map<
String, String> ? arguments, - Duration? timeout,
override
Sends a request and waits for the result of a handler.
Wildcard paths are not supported: * and > throw EventBusException.
When no handler is registered the returned future fails with
NoHandlerException. Use fire when no answer is expected.
Implementation
@override
Future<dynamic> request<T>(T data,
{List<String>? paths,
String? separator,
Map<String, String>? arguments,
Duration? timeout}) async {
_checkNotDisposed();
_rejectWildcardPaths(paths, 'request');
final topic = Topic.create<T>(
paths: paths, separator: separator ?? defaultTopicPathSeparator);
final registration = _resolveHandler(topic);
if (registration == null || !registration.accepts(data)) {
_addAllEvent(
EventDTO<T>(data, topic: topic, arguments: arguments), false);
throw NoHandlerException(topic.topic);
}
final handlerNode = _nodeByTopic(registration.topic);
final previous = handlerNode?.currentData;
final dto = EventDTO<T>(data, topic: topic, arguments: arguments);
final matched = _dispatchToListeners(dto);
_addAllEvent(dto, matched);
final future = _invoke(registration, dto, previous);
return timeout == null ? await future : await future.timeout(timeout);
}