performDocumentSearchWatch method

  1. @override
Stream<QueryResult> performDocumentSearchWatch(
  1. DocumentSearchWatchRequest request
)
override

Implementation

@override
Stream<QueryResult> performDocumentSearchWatch(
    DocumentSearchWatchRequest request) async* {
  // Do we need to delegate to the master?
  switch (request.reach) {
    case Reach.server:
      // No need
      break;
    default:
      // Yes we need
      yield* (super.performDocumentSearchWatch(request));
      return;
  }

  const minInterval = Duration(seconds: 5);
  var interval = request.pollingInterval ?? minInterval;
  if (interval < minInterval) {
    interval = minInterval;
  }

  // Delegate to a search engine.
  while (true) {
    // Search
    final result = await performDocumentSearch(DocumentSearchRequest(
      collection: request.collection,
      query: request.query,
      reach: request.reach,
    )).last;

    // Yield
    yield (result);

    // Wait
    await Future.delayed(interval);
  }
}