open method

  1. @override
Future<ByteCall> open(
  1. Method method, {
  2. CallOptions options = const CallOptions(),
})
override

Implementation

@override
Future<ByteCall> open(Method method,
    {CallOptions options = const CallOptions()}) async {
  if (_closed) throw RpcError(14, 'Host is closed');
  options.validate();
  _started = true;
  final registration = _methods[method.path];
  final call = _InProcessCall(this, method, options);
  _calls.add(call);
  if (registration == null) {
    call._finish(RpcError(12, 'Unknown method ${method.path}'));
  } else if (registration.method.requestStream != method.requestStream ||
      registration.method.responseStream != method.responseStream) {
    call._finish(RpcError(3, 'Method cardinality mismatch'));
  } else if (!call._finished) {
    unawaited(Future<void>(() async {
      try {
        await registration.handler(_ServiceCall(call));
        call._finish();
      } catch (error) {
        call._finish(error is RpcError
            ? error
            : RpcError(13, 'Service handler failed: $error'));
      }
    }));
  }
  return call;
}