@Override public void call(Subscriber<? super T> subscriber) { if (refresh.compareAndSet(true, false)) { current = source.cache(); } current.unsafeSubscribe(subscriber); }
@Override public void onError(Throwable e) { long p = produced; if (p != 0L) { arbiter.produced(p); } Observable<T> o; try { o = onError.call(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); actual.onError(new CompositeException(e, ex)); return; } if (o == null) { actual.onError( new NullPointerException("The onError function returned a null Observable.")); } else { o.unsafeSubscribe(new ResumeSubscriber<T>(actual, arbiter)); } }
@Override public void call(Subscriber<? super TResult> child) { Observable<TResult> observable; ConnectableObservable<TIntermediate> connectable; try { connectable = new OperatorMulticast<TInput, TIntermediate>(source, subjectFactory); observable = resultSelector.call(connectable); } catch (Throwable t) { child.onError(t); return; } final SafeSubscriber<TResult> s = new SafeSubscriber<TResult>(child); observable.unsafeSubscribe(s); connectable.connect( new Action1<Subscription>() { @Override public void call(Subscription t1) { s.add(t1); } }); }
@Override public void onCompleted() { long p = produced; if (p != 0L) { arbiter.produced(p); } onCompleted.unsafeSubscribe(new ResumeSubscriber<T>(actual, arbiter)); }
@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); }
@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); }
@Override public void call(final Subscriber<? super T> subscriber) { try { // create the resource final Resource resource = resourceFactory.call(); // create an action/subscription that disposes only once final DisposeAction<Resource> disposeOnceOnly = new DisposeAction<Resource>(dispose, resource); // dispose on unsubscription subscriber.add(disposeOnceOnly); // create the observable final Observable<? extends T> source = observableFactory // create the observable .call(resource); final Observable<? extends T> observable; // supplement with on termination disposal if requested if (disposeEagerly) observable = source // dispose on completion or error .doOnTerminate(disposeOnceOnly); else observable = source; try { // start observable.unsafeSubscribe(Subscribers.wrap(subscriber)); } catch (Throwable e) { Throwable disposeError = disposeEagerlyIfRequested(disposeOnceOnly); Exceptions.throwIfFatal(e); Exceptions.throwIfFatal(disposeError); if (disposeError != null) subscriber.onError(new CompositeException(Arrays.asList(e, disposeError))); else // propagate error subscriber.onError(e); } } catch (Throwable e) { // then propagate error Exceptions.throwOrReport(e, subscriber); } }
void subscribeNext() { Observable<? extends T> t; synchronized (guard) { t = queue.peek(); if (t == null || active >= maxConcurrency) { return; } active++; queue.poll(); } MergeItemSubscriber itemSub = new MergeItemSubscriber(SOURCE_INDEX.getAndIncrement(this)); subscribers.add(itemSub); csub.add(itemSub); WIP.incrementAndGet(this); t.unsafeSubscribe(itemSub); request(1); }
private void handleResult(Observable<Void> aResult) { ChainSubscriber nextSubscriber = new ChainSubscriber(subscription, context, request, response, child); subscription.set(nextSubscriber); aResult.unsafeSubscribe(nextSubscriber); }