everAll function

Worker everAll(
  1. List<RxInterface> listeners,
  2. dynamic callback(
    1. dynamic
    ),
  3. {dynamic condition = true}
)

Similar to ever, but takes a list of listeners, the condition for the callback is common to all listeners, and the callback is executed to each one of them. The Worker is common to all, so worker.dispose() will cancel all streams.

Implementation

Worker everAll(List<RxInterface> listeners, Function(dynamic) callback,
    {dynamic condition = true}) {
  final evers = <StreamSubscription>[];
  for (var i in listeners) {
    final sub = i.subject.stream.listen((event) {
      if (_conditional(condition)) callback(event);
    });
    evers.add(sub);
  }

  Future<void> cancel() {
    for (var i in evers) {
      i.cancel();
    }
    return Future.value(() {});
  }

  return Worker(cancel, '[everAll]');
}