Пример #1
0
  @Override
  public Subscription subscribe(EventObserver<E> observer) {

    EventSubscriber<E> flattenSubscriber = new EventSubscriber<>(observer);

    CompositeSubscription subscriptions = new CompositeSubscription();

    Subscription streamSub =
        streamOfStreams
            .map(stream -> stream.onEvent(flattenSubscriber::onEvent))
            .observe(EventObserver.create(subscriptions::add, flattenSubscriber::onCompleted));

    subscriptions.add(streamSub);

    flattenSubscriber.doOnDispose(subscriptions::dispose);

    return flattenSubscriber;
  }
Пример #2
0
  @Override
  public EventSubscriber<T> apply(EventSubscriber<T> childSubscriber) {

    EventObserver<T> sourceObserver =
        EventObserver.create(
            value -> {
              if (predicate.test(value)) childSubscriber.onEvent(value);
            },
            childSubscriber::onCompleted);

    return new EventSubscriber<>(sourceObserver);
  }