uniqueEach<T> method

StreamSubscription<T> uniqueEach<T>(
  1. Symbol id,
  2. Stream<T> stream,
  3. void fn(
    1. T item
    )
)

Listens and iterates through stream by calling fn. The listener is disposed in the dispose function.

If you add a uniqueId, it means that whenever you call each, we will make sure that clear any listener with the same uniqueId.

Implementation

StreamSubscription<T> uniqueEach<T>(
    Symbol id, Stream<T> stream, void Function(T item) fn) {
  late StreamSubscription<T> ret;

  _sanity();

  ret = ControlledStreamSubscription(
      stream.listen(fn), () => _uniqueSubs.remove(id));

  _uniqueSubs[id]?.cancel();

  _uniqueSubs[id] = ret;

  return ret;
}