@Override
 public Subscription onSubscribe(Observer<? super GroupedObservable<TKey, TResult>> t1) {
   SerialSubscription cancel = new SerialSubscription();
   ResultSink sink = new ResultSink(t1, cancel);
   cancel.set(sink.run());
   return cancel;
 }
    /** Prepare the subscription tree. */
    public Subscription run() {
      SerialSubscription toSource = new SerialSubscription();
      group.add(toSource);

      toSource.set(source.subscribe(this));

      return group;
    }
    @Override
    public void onNext(TSource args) {
      TKey key;
      TResult value;
      try {
        key = keySelector.call(args);
        value = valueSelector.call(args);
      } catch (Throwable t) {
        onError(t);
        return;
      }

      GroupSubject<TKey, TResult> g;
      boolean newGroup = false;
      synchronized (key) {
        g = map.get(key);
        if (g == null) {
          g = create(key);
          map.put(key, g);
          newGroup = true;
        }
      }

      if (newGroup) {
        Observable<? extends TDuration> duration;
        try {
          duration = durationSelector.call(g.toObservable());
        } catch (Throwable t) {
          onError(t);
          return;
        }

        synchronized (gate) {
          observer.onNext(g.toObservable());
        }

        SerialSubscription durationHandle = new SerialSubscription();
        group.add(durationHandle);

        DurationObserver durationObserver = new DurationObserver(key, durationHandle);
        durationHandle.set(duration.subscribe(durationObserver));
      }

      synchronized (gate) {
        g.onNext(value);
      }
    }
  @Override
  public void call(Subscriber<? super T> t) {
    final SerialSubscription serial = new SerialSubscription();

    t.add(serial);

    final Subscriber<T> child = Subscribers.wrap(t);

    Subscriber<U> otherSubscriber =
        new Subscriber<U>() {
          boolean done;

          @Override
          public void onNext(U t) {
            onCompleted();
          }

          @Override
          public void onError(Throwable e) {
            if (done) {
              RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
              return;
            }
            done = true;
            child.onError(e);
          }

          @Override
          public void onCompleted() {
            if (done) {
              return;
            }
            done = true;
            serial.set(Subscriptions.unsubscribed());

            main.unsafeSubscribe(child);
          }
        };

    serial.set(otherSubscriber);

    other.unsafeSubscribe(otherSubscriber);
  }
Beispiel #5
0
 @Override
 public void onNext(Observable<? extends T> t) {
   final int id;
   synchronized (guard) {
     id = ++index;
     active = true;
     currentSubscriber = new InnerSubscriber<T>(id, arbiter, this);
   }
   ssub.set(currentSubscriber);
   t.unsafeSubscribe(currentSubscriber);
 }
 private void handleResult(Observable<Void> aResult) {
   ChainSubscriber nextSubscriber =
       new ChainSubscriber(subscription, context, request, response, child);
   subscription.set(nextSubscriber);
   aResult.unsafeSubscribe(nextSubscriber);
 }