registerStream method

Stream registerStream(
  1. Stream stream, {
  2. Stream? replaces,
  3. bool initialNotification = true,
})

Starts listening on value changes (if not already doing so).

Implementation

Stream registerStream(Stream stream,
    {Stream? replaces, bool initialNotification = true}) {
  if (_subscriptions.containsKey(stream)) {
    // little sanity check
    assert(replaces == null);
    // nothing to do, already listening
    return stream;
  }
  if (replaces != null) {
    unregisterStream(replaces);
  }
  StackTrace? stackTrace;
  assert(() {
    // stackTrace is only used in debugging
    if (_withStackTrace) {
      stackTrace = StackTrace.current;
    }
    return true;
  }());
  _subscriptions[stream] = stream.listen((_) {
    if (stackTrace != null) {
      print("Coalescer notified from $stackTrace");
    }
    notifyChange();
  });
  if (initialNotification) {
    notifyChange();
  }
  return stream;
}