snapshot method

Future snapshot({
  1. int? timeout,
})

Snapshot the current value without subscribing to updates.

Implementation

Future<TTValue?> snapshot({int? timeout}) async {
  // Guard against any potential re-entrancy by querying the graph directly.
  final completer = Completer<TTValue?>();
  VoidCallback dispose = () {};
  var completed = false;

  void onValue(TTValue? value, [String? _, dynamic __]) {
    if (completed) return;
    completed = true;
    completer.complete(value);
    dispose();
  }

  final path = getPath();
  dispose = _client.graph.query(path, onValue);
  final souls = await _client.graph.getPathSouls(path);
  for (final soul in souls) {
    final cleanup = _client.graph.get(soul);
    cleanup();
  }
  return completer.future;
}