@CheckResult @NonNull public static Completable subscribeOn( @NonNull StorIOSQLite storIOSQLite, @NonNull Completable completable ) { final Scheduler scheduler = storIOSQLite.defaultScheduler(); return scheduler != null ? completable.subscribeOn(scheduler) : completable; } }
@Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } });
@Override public Completable deleteByResourceGroupAsync(String groupName, String name) { return this.deleteInnerAsync(groupName, name).subscribeOn(SdkContext.getRxScheduler()); }
@Override public Completable deleteByResourceGroupAsync(String groupName, String name) { return this.deleteInnerAsync(groupName, name).subscribeOn(SdkContext.getRxScheduler()); }
@Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } });
@Override public Completable adapt(Call call) { Completable completable = Completable.create(new CompletableCallOnSubscribe(call)); if (scheduler != null) { return completable.subscribeOn(scheduler); } return completable; } }
@Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } });
@Override public Completable deleteByResourceGroupAsync(String groupName, String name) { return this.deleteInnerAsync(groupName, name).subscribeOn(SdkContext.getRxScheduler()); }
@Override public Observable<R> call(final T value) { Completable completable = func.call(value); if (scheduler != null) { completable = completable.subscribeOn(scheduler); } return completable .toObservable() .ignoreElements() .map( new Func1<Object, R>() { @Override public R call(Object ignored) { // Since our upstream has ignoreElements on it, values will never ever be emitted, and // therefore this function call won't actually be executed. This map is really only present // in order to cast the stream to type R. Throwing an exception in this never-to-be-executed // function allows us say that the return type is T without actually needing to be able // to produce values of type T. throw new IllegalStateException( "Impossible state! ignoreElements() mustn't allow values to be emitted!"); } }); } });
@Override public Completable invokeAfterPostRunAsync(final boolean isGroupFaulted) { if (actualTaskItem.isHot()) { return Completable.defer(new Func0<Completable>() { @Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } }); } else { return this.actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } } }
@Override public Completable invokeAfterPostRunAsync(final boolean isGroupFaulted) { if (actualTaskItem.isHot()) { return Completable.defer(new Func0<Completable>() { @Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } }); } else { return this.actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } } }
@Override public Completable invokeAfterPostRunAsync(final boolean isGroupFaulted) { if (actualTaskItem.isHot()) { return Completable.defer(new Func0<Completable>() { @Override public Completable call() { return actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } }); } else { return this.actualTaskItem.invokeAfterPostRunAsync(isGroupFaulted) .subscribeOn(Schedulers.immediate()); } } }
@Test public void testInterrupt() throws InterruptedException { final int count = 1000; CountDownLatch latch = new CountDownLatch(count); for (int i = 0; i < count; i++) { Completable.complete() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) // The problem does not occur if you comment out this line .andThen(Completable.fromAction(() -> { try { Thread.sleep(3000); } catch (InterruptedException e) { System.out.println("Interrupted!"); // This is output periodically } })) .subscribe(() -> latch.countDown()); } latch.await(); //testInterrupt(); } }
@Test public void test() { Subscription subscription1 = Completable.fromCallable(() -> { Thread.sleep(1000); System.out.println("first Callable executed"); return 0; }) .subscribeOn(scheduler) .subscribe(); Subscription subscription2 = Completable.fromCallable(() -> { Thread.sleep(1000); System.out.println("second Callable executed"); return 0; }) .subscribeOn(scheduler) .subscribe(); CompositeSubscription subscriptions = new CompositeSubscription(); subscriptions.addAll(subscription1, subscription2); subscriptions.clear(); } }
@Test public void test() throws Exception { System.out.println("Testing Completable.concat"); System.out.println(); Completable.concat( Observable.range(1, 5).map(integer -> Completable.fromAction(() -> { try { System.out.println("Processing " + integer + "..."); Thread.sleep(100); System.out.println("Processing " + integer + " finished"); } catch (InterruptedException e) { e.printStackTrace(); } }) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from " + integer)) .subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()) ) .doOnUnsubscribe(() -> System.out.println("Unsubscribed from parent observable")) ).subscribe(() -> { System.out.println("Finished Completable.concat"); }, Throwable::printStackTrace ); Thread.sleep(2000); } }
return job.subscribeOn(Schedulers.io());