@Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(SubscriptionHelper.empty()); }
/** * Calls onSubscribe on the target Subscriber with the empty instance followed by a call to onComplete. * * @param s */ public static void complete(Subscriber<?> s) { s.onSubscribe(SubscriptionHelper.empty()); s.onComplete(); }
/** * Calls onSubscribe on the target Subscriber with the empty instance followed by a call to onError with the * supplied error. * * @param s * @param e */ public static void error(Subscriber<?> s, Throwable e) { s.onSubscribe(SubscriptionHelper.empty()); s.onError(e); }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.s, s)) { this.s = s; try { parent.onSubscribe.accept(s); } catch (Throwable ex) { ExceptionHelper.throwIfFatal(ex); s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(ex); return; } actual.onSubscribe(this); } }
@Override public void onSubscribe(Subscription s) { if(parent.onSubscribeCall() != null) { try { parent.onSubscribeCall().accept(s); } catch (Throwable e) { s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(e); return; } } this.s = s; actual.onSubscribe(this); }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.s, s)) { this.s = s; try { parent.onSubscribe.accept(s); } catch (Throwable ex) { ExceptionHelper.throwIfFatal(ex); s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(ex); return; } actual.onSubscribe(this); } }
@SuppressWarnings("unchecked") @Override public void onSubscribe(Subscription s) { if(parent.onSubscribeCall() != null) { try { parent.onSubscribeCall().accept(s); } catch (Throwable e) { s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(e); return; } } this.s = (QueueSubscription<T>)s; actual.onSubscribe(this); }
void handleTimeout() { if (other == null) { super.cancel(); subscriber.onError(new TimeoutException()); } else { set(SubscriptionHelper.empty()); other.subscribe(new PublisherTimeoutOtherSubscriber<>(subscriber, this)); } }
@Override public void onSubscribe(Subscription s) { if(parent.onSubscribeCall() != null) { try { parent.onSubscribeCall().accept(s); } catch (Throwable e) { s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(e); return; } } this.s = s; actual.onSubscribe(this); }
@SuppressWarnings("unchecked") @Override public void onSubscribe(Subscription s) { if(parent.onSubscribeCall() != null) { try { parent.onSubscribeCall().accept(s); } catch (Throwable e) { s.cancel(); actual.onSubscribe(SubscriptionHelper.empty()); onError(e); return; } } this.s = (QueueSubscription<T>)s; actual.onSubscribe(this); }
@Override public void subscribe(Subscriber<? super T> s) { PublisherRetryWhenOtherSubscriber other = new PublisherRetryWhenOtherSubscriber(); Subscriber<Throwable> signaller = new SerializedSubscriber<>(other.completionSignal); signaller.onSubscribe(SubscriptionHelper.empty()); Subscriber<T> serial = new SerializedSubscriber<>(s); PublisherRetryWhenMainSubscriber<T> main = new PublisherRetryWhenMainSubscriber<>(serial, signaller, source); other.main = main; serial.onSubscribe(main); Publisher<? extends Object> p; try { p = whenSourceFactory.apply(other); } catch (Throwable e) { ExceptionHelper.throwIfFatal(e); s.onError(ExceptionHelper.unwrap(e)); return; } if (p == null) { s.onError(new NullPointerException("The whenSourceFactory returned a null Publisher")); return; } p.subscribe(other); if (!main.cancelled) { source.subscribe(main); } }
@Override public void subscribe(Subscriber<? super T> s) { PublisherRepeatWhenOtherSubscriber other = new PublisherRepeatWhenOtherSubscriber(); Subscriber<Long> signaller = new SerializedSubscriber<>(other.completionSignal); signaller.onSubscribe(SubscriptionHelper.empty()); Subscriber<T> serial = new SerializedSubscriber<>(s); PublisherRepeatWhenMainSubscriber<T> main = new PublisherRepeatWhenMainSubscriber<>(serial, signaller, source); other.main = main; serial.onSubscribe(main); Publisher<?> p; try { p = whenSourceFactory.apply(other); } catch (Throwable e) { ExceptionHelper.throwIfFatal(e); s.onError(ExceptionHelper.unwrap(e)); return; } if (p == null) { s.onError(new NullPointerException("The whenSourceFactory returned a null Publisher")); return; } p.subscribe(other); if (!main.cancelled) { source.subscribe(main); } }
@Override public void onNext(T t) { long idx = INDEX.incrementAndGet(this); if (!SubscriptionHelper.set(OTHER, this, SubscriptionHelper.empty())) { return; } Publisher<U> p; try { p = throttler.apply(t); } catch (Throwable e) { ExceptionHelper.throwIfFatal(e); onError(ExceptionHelper.unwrap(e)); return; } if (p == null) { onError(new NullPointerException("The throttler returned a null publisher")); return; } PublisherThrottleTimeoutOther<T, U> os = new PublisherThrottleTimeoutOther<>(this, t, idx); if (SubscriptionHelper.replace(OTHER, this, os)) { p.subscribe(os); } }
@Test public void subscribeLambdaError() { TestSubscriber<Integer> ts = new TestSubscriber<>(); ts.onSubscribe(SubscriptionHelper.empty()); Px.<Integer>error(new RuntimeException("forced failure")) .subscribe(ts::onNext, ts::onError, ts::onComplete); ts.assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("forced failure") .assertNotComplete(); }
@Test public void takeOverflowAttempt() { TestSubscriber<Integer> ts = new TestSubscriber<>(); Publisher<Integer> p = s -> { s.onSubscribe(SubscriptionHelper.empty()); s.onNext(1); s.onNext(2); s.onNext(3); }; new PublisherTake<>(p, 2).subscribe(ts); ts.assertValues(1, 2) .assertNoError() .assertComplete(); } }
@Test public void subscribeLambdaEmpty() { TestSubscriber<Integer> ts = new TestSubscriber<>(); ts.onSubscribe(SubscriptionHelper.empty()); Px.<Integer>empty().subscribe(ts::onNext, ts::onError, ts::onComplete); ts.assertNoValues() .assertNoError() .assertComplete(); }
@Test public void subscribeLambdaJust() { TestSubscriber<Integer> ts = new TestSubscriber<>(); ts.onSubscribe(SubscriptionHelper.empty()); Px.just(1).subscribe(ts::onNext, ts::onError, ts::onComplete); ts.assertValue(1) .assertNoError() .assertComplete(); }