Skip to content

Commit e45ad74

Browse files
committed
Simplify AsyncUtils
1 parent 307ad94 commit e45ad74

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/main/java/ch/petikoch/examples/mvvm_rxjava/utils/AsyncUtils.java

+3-14
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,9 @@ public static Single<FinishedIndicator> executeAsync(Runnable runnable) {
6666
public static <T> Single<T> executeAsync(Callable<T> callable) {
6767
AsyncSubject<T> resultSubject = AsyncSubject.create();
6868

69-
final Subscription asyncOp = Observable.<T>create(singleSubscriber -> {
70-
try {
71-
T result = callable.call();
72-
if (!singleSubscriber.isUnsubscribed()) {
73-
singleSubscriber.onNext(result);
74-
}
75-
} catch (Exception e) {
76-
if (!singleSubscriber.isUnsubscribed()) {
77-
singleSubscriber.onError(e);
78-
}
79-
}
80-
}).subscribeOn(Schedulers.io())
81-
.first()
82-
.lift(preserveFullStackTrace())
69+
final Subscription asyncOp = Observable.fromCallable(callable)
70+
.subscribeOn(Schedulers.io())
71+
.lift(preserveFullStackTrace())
8372
.subscribe(
8473
t -> {
8574
resultSubject.onNext(t);

0 commit comments

Comments
 (0)