sendAll<T> method

Future<List<JsonRpcResponse<T>>> sendAll<T>(
  1. List<JsonRpcRequest> request,
  2. JsonRpcResponseDecoder<List<Map<String, dynamic>>, List<JsonRpcResponse<T>>> decode, {
  3. JsonRpcClientConfig? config,
  4. bool eagerError = false,
})

Sends a batch JSON RPC request to uri and returns its response.

The decode method is used to convert the JSON response to a JsonRpcResponse.

The config object can be used to configure the request.

Set eagerError to complete the future with a call to Future.error containing the first error (JsonRpcException) found in the response.

Implementation

Future<List<JsonRpcResponse<T>>> sendAll<T>(
  final List<JsonRpcRequest> request,
  final JsonRpcResponseDecoder<List<Map<String, dynamic>>, List<JsonRpcResponse<T>>> decode, {
  final JsonRpcClientConfig? config,
  final bool eagerError = false,
}) async {
  if (request.isEmpty) return const [];
  final List<int> body = await encoder.convert(request);
  final List result = await handler(body, config: config, id: request.first.id);
  final List<Map<String, dynamic>> json = result.cast<Map<String, dynamic>>();
  final List<JsonRpcResponse<T>> response = decode(json);
  return eagerError ? _errorOrValue(response) : Future.value(response);
}