useStream<T> method

AsyncEntry<T> useStream<T>(
  1. Key key,
  2. Stream<T> factory()
)

Implementation

AsyncEntry<T> useStream<T>(Key key, Stream<T> Function() factory) {
  _seenThisFrame.add(key);
  final existing = _entries[key];
  if (existing != null) return existing as AsyncEntry<T>;
  final entry = AsyncEntry<T>();
  entry.active = true;
  _entries[key] = entry;
  final gen = Object();
  entry.gen = gen;
  entry.subscription = factory().listen((value) {
    if (entry.gen != gen || !entry.active) return;
    entry.status = AsyncStatus.success;
    entry.value = value;
    _notifyResolved(key);
  }, onError: (e, st) {
    if (entry.gen != gen || !entry.active) return;
    entry.status = AsyncStatus.error;
    entry.error = e;
    entry.stack = st;
    _notifyResolved(key);
  }, onDone: () {
    if (entry.gen != gen || !entry.active) return;
    entry.status = AsyncStatus.success;
    _notifyResolved(key);
  });
  return entry;
}