Completable.complete() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) .andThen(Completable.fromAction(new Action() { @Override public void run() throws Exception { .subscribe(new Action() { @Override public void run() throws Exception {
@Test public void onErrorThrows2() { Completable.create(new CompletableOnSubscribe() { @Override public void subscribe(CompletableEmitter e) throws Exception { try { e.onError(new IOException()); fail("Should have thrown"); } catch (TestException ex) { // expected } assertTrue(e.isDisposed()); } }).subscribe(new CompletableObserver() { @Override public void onSubscribe(Disposable d) { } @Override public void onError(Throwable e) { throw new TestException(); } @Override public void onComplete() { } }); }
private void doSomeWork() { Completable completable = Completable.timer(1000, TimeUnit.MILLISECONDS); completable .subscribeOn(Schedulers.io()) // Be notified on the main thread .observeOn(AndroidSchedulers.mainThread()) .subscribe(getCompletableObserver()); }
@Override public void run() { c.subscribe(to1); } };
Completable c0 = Completable.fromAction(new Action() { @Override public void run() throws Exception { Completable.concat(Arrays.asList(Completable.complete() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()), c0) .subscribe(new Action() { @Override public void run() throws Exception {
@Test public void noWinnerCompleteDispose() throws Exception { for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { final AtomicBoolean interrupted = new AtomicBoolean(); final CountDownLatch cdl = new CountDownLatch(1); Completable.ambArray( Completable.complete() .subscribeOn(Schedulers.single()) .observeOn(Schedulers.computation()), Completable.never() ) .subscribe(new Action() { @Override public void run() throws Exception { interrupted.set(Thread.currentThread().isInterrupted()); cdl.countDown(); } }); assertTrue(cdl.await(500, TimeUnit.SECONDS)); assertFalse("Interrupted!", interrupted.get()); } } }
@Test public void noWinnerErrorDispose() throws Exception { final TestException ex = new TestException(); for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) { final AtomicBoolean interrupted = new AtomicBoolean(); final CountDownLatch cdl = new CountDownLatch(1); Completable.ambArray( Completable.error(ex) .subscribeOn(Schedulers.single()) .observeOn(Schedulers.computation()), Completable.never() ) .subscribe(Functions.EMPTY_ACTION, new Consumer<Throwable>() { @Override public void accept(Throwable e) throws Exception { interrupted.set(Thread.currentThread().isInterrupted()); cdl.countDown(); } }); assertTrue(cdl.await(500, TimeUnit.SECONDS)); assertFalse("Interrupted!", interrupted.get()); } }
private void updateSubscription(final ChannelInfo info) { if (DEBUG) Log.d(TAG, "updateSubscription() called with: info = [" + info + "]"); final Action onComplete = () -> { if (DEBUG) Log.d(TAG, "Updated subscription: " + info.getUrl()); }; final Consumer<Throwable> onError = (@NonNull Throwable throwable) -> onUnrecoverableError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(info.getServiceId()), "Updating Subscription for " + info.getUrl(), R.string.subscription_update_failed); disposables.add(subscriptionService.updateChannelInfo(info) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(onComplete, onError)); }
private void saveImmediate() { if (playlistManager == null || itemListAdapter == null) return; // List must be loaded and modified in order to save if (isLoadingComplete == null || isModified == null || !isLoadingComplete.get() || !isModified.get()) { Log.w(TAG, "Attempting to save playlist when local playlist " + "is not loaded or not modified: playlist id=[" + playlistId + "]"); return; } final List<LocalItem> items = itemListAdapter.getItemsList(); List<Long> streamIds = new ArrayList<>(items.size()); for (final LocalItem item : items) { if (item instanceof PlaylistStreamEntry) { streamIds.add(((PlaylistStreamEntry) item).streamId); } } Log.d(TAG, "Updating playlist id=[" + playlistId + "] with [" + streamIds.size() + "] items"); final Disposable disposable = playlistManager.updateJoin(playlistId, streamIds) .observeOn(AndroidSchedulers.mainThread()) .subscribe( () -> { if (isModified != null) isModified.set(false); }, this::onError ); disposables.add(disposable); }
@Test public void failSingleCompletableBlockingAwait() { try { RxJavaPlugins.setFailOnNonBlockingScheduler(true); Completable.complete() .subscribeOn(Schedulers.single()) .doOnComplete(new Action() { @Override public void run() throws Exception { Completable.complete().delay(10, TimeUnit.SECONDS).blockingAwait(); } }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IllegalStateException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void normal() { TestResourceCompletableObserver rco = new TestResourceCompletableObserver(); assertFalse(rco.isDisposed()); assertEquals(0, rco.start); assertTrue(rco.errors.isEmpty()); Completable.complete().subscribe(rco); assertTrue(rco.isDisposed()); assertEquals(1, rco.start); assertEquals(1, rco.complete); assertTrue(rco.errors.isEmpty()); }
@Test public void normal() { List<Throwable> list = TestHelper.trackPluginErrors(); try { TestScheduler scheduler = new TestScheduler(); TestObserver<Void> to = Completable.complete() .subscribeOn(scheduler) .test(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); to.assertResult(); assertTrue(list.toString(), list.isEmpty()); } finally { RxJavaPlugins.reset(); } }
Completable fromCallableObservable = Completable.fromCallable(func); .subscribeOn(Schedulers.computation()) .subscribe(outer);