requestStrict<Params> method

  1. @override
Future requestStrict<Params>({
  1. required JsonRpcRequest<Params> request,
  2. dynamic context,
})
override

Implementation

@override
Future<dynamic> requestStrict<Params>({
  required JsonRpcRequest<Params> request,
  dynamic context,
}) async {
  if (!connection.connected) {
    try {
      await open();
    } catch (e) {
      throw WCException(e.toString());
    }
  }

  try {
    final completer = Completer<dynamic>();
    events.once(request.id.toString(), (data) {
      if (isJsonRpcError(data)) {
        completer.completeError(
            JsonRpcError.fromJson(data as Map<String, dynamic>).error!);
      } else {
        completer.complete((data as Map<String, dynamic>)['result']);
      }
    });
    await connection.send(payload: request, context: context);
    return completer.future;
  } catch (e) {
    throw WCException(e.toString());
  }
}