Skip to content

Commit

Permalink
2.x: Make Flowable.fromCallable consitent with the other fromCallables (
Browse files Browse the repository at this point in the history
#6158)

2.x: Make Flowable.fromCallable consistent with the other fromCallables
  • Loading branch information
akarnokd authored Aug 14, 2018
1 parent 835ab00 commit 7d65291
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.reactivex.exceptions.Exceptions;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.subscriptions.DeferredScalarSubscription;
import io.reactivex.plugins.RxJavaPlugins;

public final class FlowableFromCallable<T> extends Flowable<T> implements Callable<T> {
final Callable<? extends T> callable;
Expand All @@ -38,7 +39,11 @@ public void subscribeActual(Subscriber<? super T> s) {
t = ObjectHelper.requireNonNull(callable.call(), "The callable returned a null value");
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
s.onError(ex);
if (deferred.isCancelled()) {
RxJavaPlugins.onError(ex);
} else {
s.onError(ex);
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package io.reactivex.internal.operators.flowable;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;

import java.util.List;
import java.util.concurrent.*;

import org.junit.Test;
Expand All @@ -27,7 +29,9 @@
import org.reactivestreams.*;

import io.reactivex.*;
import io.reactivex.exceptions.TestException;
import io.reactivex.functions.Function;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.TestSubscriber;

Expand Down Expand Up @@ -238,4 +242,27 @@ public Object call() throws Exception {
.test()
.assertFailure(NullPointerException.class);
}

@Test(timeout = 5000)
public void undeliverableUponCancellation() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

Flowable.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
ts.cancel();
throw new TestException();
}
})
.subscribe(ts);

ts.assertEmpty();

TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}

0 comments on commit 7d65291

Please sign in to comment.