read method

QueryOptions<O> read(
  1. RpcClient rpc,
  2. I input, {
  3. required List<String> scope,
  4. QueryPolicy policy = const QueryPolicy(),
})

Snapshots this input with this ref's codec and the client's serializer.

Returns native options. Rebuilding them updates future definitions without replacing same-key observers or in-flight work. Input is not re-encoded when sending. Credentials are obtained from the owning client at send time. Relative Web URLs follow the document base; native reads need an explicit HTTP(S) endpoint. Raw ServerResponse and streaming results are not values for this cache. Use direct RPC for those resources.

Cancellation stops client work and excludes late results. Server-side cooperative cancellation depends on the transport observing disconnects.

Implementation

QueryOptions<O> read(
  RpcClient rpc,
  I input, {
  required List<String> scope,
  QueryPolicy policy = const QueryPolicy(),
}) {
  final capturedScope = _scope(scope);
  final call = prepareRpcRead(rpc, this, input);
  return QueryOptions<O>(
    key: QueryKey<O>('rpc', [
      ..._prefix(call.endpoint, capturedScope),
      jsonDecode(call.payload),
    ]),
    policy: policy,
    query: (context) async {
      final value = await call(
        cancelled: context.cancelToken.whenCancelled.then<void>((_) {}),
      );
      if (value is ServerResponse) {
        try {
          await value.body.listen(null, onError: (Object _) {}).cancel();
        } on Object {
          // Cleanup must not replace the unsupported-value diagnostic.
        }
        throw UnsupportedError(_valueOnly);
      }
      if (value is Stream) throw UnsupportedError(_valueOnly);
      return value;
    },
  );
}