/** * Caches the value or error event of the upstream Perhaps * and relays/replays it to Subscribers. * @return the new Perhaps instance * * @since 0.14.1 */ public final Perhaps<T> cache() { return onAssembly(new PerhapsCache<T>(this)); }
@SuppressWarnings("unchecked") @Override public void cancel() { super.cancel(); Object o = parent.get(); if (o != null && parent.compareAndSet(o, null)) { ((PerhapsCache<T>)o).remove(this); } }
@Override protected void subscribeActual(Subscriber<? super T> s) { CacheSubscription<T> inner = new CacheSubscription<T>(s, this); s.onSubscribe(inner); if (add(inner)) { if (inner.isCancelled()) { remove(inner); } if (once.compareAndSet(false, true)) { source.subscribe(this); } } else { if (!inner.isCancelled()) { Throwable ex = error; if (ex != null) { inner.error(ex); } else { T v = value; if (v != null) { inner.complete(v); } else { inner.complete(); } } } } }
@Override protected void subscribeActual(Subscriber<? super T> s) { CacheSubscription<T> inner = new CacheSubscription<T>(s, this); s.onSubscribe(inner); if (add(inner)) { if (inner.isCancelled()) { remove(inner); } if (once.compareAndSet(false, true)) { source.subscribe(this); } } else { if (!inner.isCancelled()) { Throwable ex = error; if (ex != null) { inner.error(ex); } else { T v = value; if (v != null) { inner.complete(v); } else { inner.complete(); } } } } }
/** * Caches the value or error event of the upstream Perhaps * and relays/replays it to Subscribers. * @return the new Perhaps instance * * @since 0.14.1 */ public final Perhaps<T> cache() { return onAssembly(new PerhapsCache<T>(this)); }
@SuppressWarnings("unchecked") @Override public void cancel() { super.cancel(); Object o = parent.get(); if (o != null && parent.compareAndSet(o, null)) { ((PerhapsCache<T>)o).remove(this); } }