/** * Subscribes to this Perhaps and calls the appropriate callback for the resulting signal. * @param onNext called when this Perhaps succeeds * @param onError called when this Perhaps fails * @return the Disposable that allows cancelling the subscription */ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) { return subscribe(onNext, onError, Functions.EMPTY_ACTION); }
/** * Subscribe with a Subscriber (subclass) and return it as is. * @param <E> the Subscriber subclass type * @param s the soubscriber, not null * @return the {@code s} as is */ public final <E extends Subscriber<? super T>> E subscribeWith(E s) { subscribe(s); return s; }
/** * Subscribes to this Perhaps and calls the appropriate callback for the resulting signal. * @param onNext called when this Perhaps succeeds * @param onError called when this Perhaps fails * @return the Disposable that allows cancelling the subscription */ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) { return subscribe(onNext, onError, Functions.EMPTY_ACTION); }
void subscribe(Perhaps<? extends T>[] sources, int n) { ZipInnerSubscriber<T, R>[] subs = subscribers; AtomicInteger w = wip; for (int i = 0; i < n; i++) { if (w.get() <= 0) { break; } sources[i].subscribe(subs[i]); } }
@Override public void onNext(Object t) { if (upstream != SubscriptionHelper.CANCELLED) { upstream.cancel(); upstream = SubscriptionHelper.CANCELLED; source.subscribe(sourceSubscriber); } }
@Override protected void subscribeActual(Subscriber<? super R> s) { source.subscribe(new MapSubscriber<T, R>(s, mapper)); } }
/** * Subscribes to this Perhaps and calls the appropriate callback for the resulting signal. * @param onNext called when this Perhaps succeeds * @param onError called when this Perhaps fails * @param onComplete called when this Perhaps succeeds after the call to onNext * @return the Disposable that allows cancelling the subscription */ public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Action onComplete) { LambdaSubscriber<T> s = new LambdaSubscriber<T>(onNext, onError, onComplete, Functions.REQUEST_MAX); subscribe(s); return s; }
/** * Converts this Perhaps into a Future and signals its single * value or null if this Perhaps is empty. * @return the new Future instance */ public final Future<T> toFuture() { FuturePerhapsSubscriber<T> fs = new FuturePerhapsSubscriber<T>(); subscribe(fs); return fs; } }
@Override public void onComplete() { T v = value; if (v != null) { complete(v); } else { other.subscribe(otherSubscriber); } }
@Override protected void subscribeActual(Subscriber<? super T> s) { source.subscribe(new UnsubscribeOnSubscriber<T>(s, scheduler)); } }
/** * Subscribe to this Perhaps and ignore any signal it produces. * @return the Disposable that allows cancelling the subscription */ public final Disposable subscribe() { return subscribe(Functions.emptyConsumer(), Functions.ERROR_CONSUMER, Functions.EMPTY_ACTION); }
@Override public void onNext(Object t) { if (upstream != SubscriptionHelper.CANCELLED) { upstream.cancel(); upstream = SubscriptionHelper.CANCELLED; source.subscribe(sourceSubscriber); } }
@Override protected void subscribeActual(Subscriber<? super T> s) { TakeUntilSubscriber<T> parent = new TakeUntilSubscriber<T>(s); s.onSubscribe(parent); other.subscribe(parent.other); source.subscribe(parent); }
@Override protected void subscribeActual(Subscriber<? super T> s) { TimeoutSubscriber<T> parent = new TimeoutSubscriber<T>(s, fallback); s.onSubscribe(parent); other.subscribe(parent.other); source.subscribe(parent); }
@Override protected void subscribeActual(Subscriber<? super T> s) { TakeUntilSubscriber<T> parent = new TakeUntilSubscriber<T>(s); s.onSubscribe(parent); other.subscribe(parent.other); source.subscribe(parent); }
@Override protected void subscribeActual(Subscriber<? super T> s) { source.subscribe(new ObserveOnSubscriber<T>(s, scheduler.createWorker())); } }
@Override protected void subscribeActual(Subscriber<? super T> s) { Perhaps<? extends T> sp; try { sp = ObjectHelper.requireNonNull(supplier.call(), "The supplier returned a null Solo"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } sp.subscribe(s); }
@Override public void onError(Throwable t) { Perhaps<? extends R> ph; try { ph = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onErrorMapper returned a null Perhaps"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); downstream.onError(ex); return; } ph.subscribe(inner); }
@Override protected void subscribeActual(Subscriber<? super R> s) { Subscriber<? super T> parent; try { parent = ObjectHelper.requireNonNull(onLift.apply(s), "The onLift returned a null Subscriber"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); EmptySubscription.error(ex, s); return; } source.subscribe(parent); }
@Test public void subscribeThreeArgError() { Perhaps.error(new IOException()).subscribe(this, this, this); assertEquals(1, count); }