sendRequest method

Future sendRequest (String method, [ 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 = new Completer.sync();
  _pendingRequests[id] = new _Request(method, completer, new Chain.current());
  return completer.future;
}