@Override public void request(long n) { if (SubscriptionHelper.validate(n)) { if (BackpressureHelper.add(this, n) == 0) { long requested = n; long emitted = 0; do { emitted = requested; while (requested-- > 0 && !cancelled && (count == -1 || counter-- > 0)) { child.onNext(value); } } while ((requested = this.addAndGet(-emitted)) > 0); if (count >= 0 && !cancelled) { child.onComplete(); } } } }
@Override protected void subscribeActual(Subscriber<? super T> child) { Flowable<T> f; try { f = transform.apply(source); } catch (Exception e) { Exceptions.throwIfFatal(e); child.onSubscribe(SubscriptionHelper.CANCELLED); child.onError(e); return; } AtomicReference<Chain<T>> chainRef = new AtomicReference<Chain<T>>(); DestinationSerializedSubject<T> destination = new DestinationSerializedSubject<T>(child, chainRef); Chain<T> chain = new Chain<T>(transform, destination, maxIterations, maxChained, tester); chainRef.set(chain); // destination is not initially subscribed to the chain but will be when // tester function result completes destination.subscribe(child); ChainedReplaySubject<T> sub = ChainedReplaySubject.create(destination, chain, tester); chain.initialize(sub); f.onTerminateDetach() // .subscribe(sub); }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.setOnce(this, s)) { if (s instanceof QueueSubscription) { @SuppressWarnings("unchecked") QueueSubscription<R> qs = (QueueSubscription<R>) s; int m = qs.requestFusion(QueueSubscription.ANY | QueueSubscription.BOUNDARY); if (m == QueueSubscription.SYNC) { fusionMode = m; queue = qs; done = true; parent.drain(); return; } if (m == QueueSubscription.ASYNC) { fusionMode = m; queue = qs; s.request(bufferSize); return; } } s.request(bufferSize); } }
@Override public boolean cancel(boolean mayInterruptIfRunning) { for (;;) { Subscription a = s.get(); if (a == this || a == SubscriptionHelper.CANCELLED) { return false; } if (s.compareAndSet(a, SubscriptionHelper.CANCELLED)) { if (a != null) { a.cancel(); } countDown(); return true; } } }
@Override public void request(long n) { if (SubscriptionHelper.validate(n)) { Subscription s = get(); if (s != null) { scheduleRequest(); } else { requested.set(true); s = get(); if (s != null) { if (requested.getAndSet(false)) { scheduleRequest(); } } } } }
@Override public void onSubscribe(Subscription subscription) { if (SubscriptionHelper.validate(this.subscription, subscription)) { this.subscription = subscription; customer.onSubscribe(this); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.s, s)) { this.s = s; actual.onSubscribe(this); } }
@Override public void request(long n) { if (SubscriptionHelper.validate(n)) { BackpressureHelper.add(requested, n); drain(); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.s, s)) { this.s = s; actual.onSubscribe(this); s.request(bufferSize); } }
@Override public void cancel() { if (compareAndSet(false, true)) { s.cancel(); s = SubscriptionHelper.CANCELLED; } }
@Override public void onNext(T t) { if (get() != SubscriptionHelper.CANCELLED) { try { onNext.accept(t); } catch (Throwable e) { Exceptions.throwIfFatal(e); get().cancel(); onError(e); } } }
void otherError(Throwable t) { SubscriptionHelper.cancel(this); if (once.compareAndSet(false, true)) { actual.onError(t); } else { RxJavaPlugins.onError(t); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.s, s)) { this.s = s; actual.onSubscribe(this); s.request(Long.MAX_VALUE); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(upstream, s)) { upstream = s; actual.onSubscribe(this); s.request(bufferSize); } }
@Override public void onError(Throwable t) { ZipLatestCoordinator<T, ?> p = parent; if (p.errors.addThrowable(t)) { lazySet(SubscriptionHelper.CANCELLED); done = true; p.drain(); } else { RxJavaPlugins.onError(t); } }
@Override public void onSubscribe(Subscription parent) { if (SubscriptionHelper.validate(this.parent, parent)) { this.parent = parent; child.onSubscribe(this); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(upstream, s)) { this.upstream = s; actual.onSubscribe(this); } }
@Override public void onSubscribe(Subscription subscription) { if (SubscriptionHelper.validate(this.parent, subscription)) { this.parent = subscription; actual.onSubscribe(this); } }
@Override public void onError(Throwable t) { if (once.compareAndSet(false, true)) { SubscriptionHelper.cancel(inner); actual.onError(t); } else { RxJavaPlugins.onError(t); } }
@Override public void onSubscribe(Subscription parent) { if (SubscriptionHelper.validate(this.parent, parent)) { this.parent = parent; child.onSubscribe(this); parent.request(windowSize - 1); } }
@Override public void request(long n) { if (SubscriptionHelper.validate(n)) { BackpressureHelper.add(requested, n); Subscription a = s.get(); if (a != null) { a.request(n); } } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.replace(this.s, s)) { long n = requested.get(); if (n != 0L) { s.request(n); } } }
@Override public void request(long n) { if (SubscriptionHelper.validate(n)) { BackpressureHelper.add(requested, n); scheduleDrain(); } }
@Override public final void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(this.upstream, s)) { this.upstream = s; actual.onSubscribe(this); s.request(maxConcurrency); } }
@Override public void onError(Throwable t) { boolean b; try { b = predicate.test(t); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); actual.onError(new CompositeException(t, ex)); return; } if (!b) { actual.onError(t); } else { active = false; if (getAndIncrement() == 0) { do { if (SubscriptionHelper.isCancelled(s.get())) { return; } if (!active) { active = true; source.subscribe(this); } } while (decrementAndGet() != 0); } } }
@Override public void onSubscribe(Subscription s) { SubscriptionHelper.replace(this.s, s); if (!once) { once = true; actual.onSubscribe(this); } }
void innerError(Throwable t) { if (once.compareAndSet(false, true)) { SubscriptionHelper.cancel(this); actual.onError(t); } else { RxJavaPlugins.onError(t); } }
@Override public void onSubscribe(Subscription s) { if (SubscriptionHelper.validate(upstream, s)) { upstream = s; actual.onSubscribe(this); s.request(Long.MAX_VALUE); } }