@Test public void testAsync() { Observable<Integer> source = Observable.range(1, 10000); for (int i = 0; i < 100; i++) { TestObserver<Integer> to1 = new TestObserver<Integer>(); Observable<Integer> cached = source.replay().autoConnect(); cached.observeOn(Schedulers.computation()).subscribe(to1); to1.awaitTerminalEvent(2, TimeUnit.SECONDS); to1.assertNoErrors(); to1.assertTerminated(); assertEquals(10000, to1.values().size()); TestObserver<Integer> to2 = new TestObserver<Integer>(); cached.observeOn(Schedulers.computation()).subscribe(to2); to2.awaitTerminalEvent(2, TimeUnit.SECONDS); to2.assertNoErrors(); to2.assertTerminated(); assertEquals(10000, to2.values().size()); } }
public static <T> ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler) { final Observable<T> observable = co.observeOn(scheduler); return RxJavaPlugins.onAssembly(new Replay<T>(co, observable)); }
ObservableReplay extends ConnectableObservable<T> implements HasUpstreamObservableSource<T>, Disposable { public static <T> ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler) { final Observable<T> observable = co.observeOn(scheduler); return RxJavaPlugins.onAssembly(new Replay<T>(co, observable)); } }
ObservableReplay extends ConnectableObservable<T> implements HasUpstreamObservableSource<T>, Disposable { public static <T> ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler) { final Observable<T> observable = co.observeOn(scheduler); return RxJavaPlugins.onAssembly(new Replay<T>(co, observable)); } private  ObservableReplay(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                             final AtomicReference<ReplayObserver<T>> current,
                             final BufferSupplier<T> bufferFactory); }
ObservableReplay extends ConnectableObservable<T> implements HasUpstreamObservableSource<T>, Disposable { public static <T> ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler) { final Observable<T> observable = co.observeOn(scheduler); return RxJavaPlugins.onAssembly(new Replay<T>(co, observable)); } private  ObservableReplay(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                             final AtomicReference<ReplayObserver<T>> current,
                             final BufferSupplier<T> bufferFactory); static Observable<R> multicastSelector(
            final Callable<? extends ConnectableObservable<U>> connectableFactory,
            final Function<? super Observable<U>, ? extends ObservableSource<R>> selector); static ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler); @SuppressWarnings("unchecked") static ConnectableObservable<T> createFrom(ObservableSource<? extends T> source); static ConnectableObservable<T> create(ObservableSource<T> source,
            final int bufferSize); static ConnectableObservable<T> create(ObservableSource<T> source,
            long maxAge, TimeUnit unit, Scheduler scheduler); static ConnectableObservable<T> create(ObservableSource<T> source,
            final long maxAge, final TimeUnit unit, final Scheduler scheduler, final int bufferSize); @Override ObservableSource<T> source(); @Override void dispose(); @Override boolean isDisposed(); @Override void connect(Consumer<? super Disposable> connection); }
ObservableReplay extends ConnectableObservable<T> implements HasUpstreamObservableSource<T>, Disposable { public static <T> ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler) { final Observable<T> observable = co.observeOn(scheduler); return RxJavaPlugins.onAssembly(new Replay<T>(co, observable)); } private  ObservableReplay(ObservableSource<T> onSubscribe, ObservableSource<T> source,
                             final AtomicReference<ReplayObserver<T>> current,
                             final BufferSupplier<T> bufferFactory); static Observable<R> multicastSelector(
            final Callable<? extends ConnectableObservable<U>> connectableFactory,
            final Function<? super Observable<U>, ? extends ObservableSource<R>> selector); static ConnectableObservable<T> observeOn(final ConnectableObservable<T> co, final Scheduler scheduler); @SuppressWarnings("unchecked") static ConnectableObservable<T> createFrom(ObservableSource<? extends T> source); static ConnectableObservable<T> create(ObservableSource<T> source,
            final int bufferSize); static ConnectableObservable<T> create(ObservableSource<T> source,
            long maxAge, TimeUnit unit, Scheduler scheduler); static ConnectableObservable<T> create(ObservableSource<T> source,
            final long maxAge, final TimeUnit unit, final Scheduler scheduler, final int bufferSize); @Override ObservableSource<T> source(); @Override void dispose(); @Override boolean isDisposed(); @Override void connect(Consumer<? super Disposable> connection);  }