uniqueEach<T> method
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;
}