each<T> method
StreamSubscription<T>
each<T>(
- Stream<
T> stream, - void fn(
- T item
- @Deprecated('Use [uniqueEach] instead') Symbol? uniqueId,
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> each<T>(Stream<T> stream, void Function(T item) fn,
{@Deprecated('Use [uniqueEach] instead') Symbol? uniqueId}) {
late StreamSubscription<T> ret;
_sanity();
if (uniqueId == null) {
ret = ControlledStreamSubscription(
stream.listen(fn), () => _subs.remove(ret));
_subs.add(ret);
} else {
ret = ControlledStreamSubscription(
stream.listen(fn), () => _uniqueSubs.remove(uniqueId));
_uniqueSubs[uniqueId]?.cancel();
_uniqueSubs[uniqueId] = ret;
}
return ret;
}