query method
Register a response event handler for request
Implementation
@mustCallSuper
Future<KuzzleResponse> query(KuzzleRequest request) async {
if (!isReady()) {
throw KuzzleError(
'Unable to execute request: not connected to a Kuzzle server.');
}
final completer = Completer<KuzzleResponse>();
once(request.requestId!, (KuzzleResponse response) {
if (response.error != null) {
emit(ProtocolEvents.QUERY_ERROR, [response.error, request]);
return completer.completeError(response.error!);
}
return completer.complete(response);
});
try {
await send(request);
// ignore: avoid_catches_without_on_clauses
} catch (error) {
emit(ProtocolEvents.QUERY_ERROR, [error, request]);
completer.completeError(error);
}
return completer.future;
}