sendRequest method

Future sendRequest(
  1. String method, [
  2. dynamic parameters
])

Sends a JSON-RPC 2 request to invoke the given method.

If passed, parameters is the parameters for the method. This must be either an Iterable (to pass parameters by position) or a Map with String keys (to pass parameters by name). Either way, it must be JSON-serializable.

If the request succeeds, this returns the response result as a decoded JSON-serializable object. If it fails, it throws an RpcException describing the failure.

Throws a StateError if the client is closed while the request is in flight, or if the client is closed when this method is called.

Implementation

Future sendRequest(String method, [parameters]) {
  var id = _id++;
  _send(method, parameters, id);

  var completer = Completer.sync();
  _pendingRequests[id] = _Request(method, completer, Chain.current());
  return completer.future;
}