withinPass<T> method

  1. @override
Future<T> withinPass<T>(
  1. Future<T> body()
)
override

Runs body as one pass: a stretch of work whose reads may share what the pass has already established about the remote.

The sync scheduler opens one per tick. It asks every backend for its heads and then cycles the documents that moved, and a backend that validates its view of the remote on every call would otherwise validate it once for the batch and once more per document, moments apart.

The contract is narrow on purpose. Inside a pass a read may be answered from what the same pass already validated, so it may be as old as the pass. A write may not: commit and delete compare against the remote as it is, pass or no pass. Nothing outlives the pass, and a call made outside one behaves as if passes did not exist.

The default runs body and nothing else, which is the whole of it for a backend whose reads are already authoritative.

Implementation

@override
Future<T> withinPass<T>(Future<T> Function() body) {
  // A pass inside a pass is the same pass. The scheduler opens one per
  // backend around the whole tick; anything nested adds no knowledge.
  if (Zone.current[_passKey] != null) return body();
  return runZoned(body, zoneValues: {_passKey: _Pass()});
}