streamDocument method

Stream<Document?> streamDocument(
  1. String path
)

Implementation

Stream<Document?> streamDocument(String path) {
  if (_listenStreamCache.containsKey(path)) {
    return _mapDocumentStream(_listenStreamCache[path]!.stream);
  }

  final documentsTarget = Target_DocumentsTarget()..documents.add(path);
  final target = Target()..documents = documentsTarget;
  final request = ListenRequest()
    ..database = database
    ..addTarget = target;

  _listenStreamCache[path] = _ListenStreamWrapper.create(
      request,
      (requestStream) => _client.listen(requestStream,
          options: CallOptions(
              metadata: {'google-cloud-resource-prefix': database})),
      onDone: () => _listenStreamCache.remove(path));

  return _mapDocumentStream(_listenStreamCache[path]!.stream);
}