These are chat archives for ReactiveX/RxJava

19th
Feb 2017
Paco
@pakoito
Feb 19 2017 21:07
one question for RxJava 2, on a flowable
.map(new Function<Pair<String, ?>, T>() {
                    @Override
                    public T apply(Pair<String, ?> stringPair) {
                        return (T) stringPair.second;
                    }
                })
in case of a ClassCastException I'm not getting a call to public void onError(Throwable e)
instead it just goes and fails completely
in RxJava2 it'll go to onError with a ClasCastException that I'd be testing as
                    @Override
                    public void onError(Throwable e) {
                        if (!(e instanceof ClassCastException)) {
                            Assert.fail(e.getMessage());
                        }
                    }
Paco
@pakoito
Feb 19 2017 21:14
it seems like in RxJava1 the subscription to the original value in line 284 never returns an exception, only the one in 266, whereas in RxJava2 it fails for 284 immediately
book.write(key, wrongValue).test().assertError(ClassCastException.class)
that just works
which is weird, because write is subscribed with the correct type, and it's only the forwarding that triggers the exception
RxJava 2 propagates from here into write, RxJava 1 does it into the updates subject: https://github.com/pakoito/RxPaper/blob/master/library/src/main/java/com/pacoworks/rxpaper/RxPaperBook.java#L151
and moving the subject call to onNext to a doAfterTerminate doesn't fix it
oh well, behaviour changes then
Paco
@pakoito
Feb 19 2017 21:22
public <T> Completable write(final String key, final T value) {
        return Completable.fromAction(new Action() {
            @Override
            public void run() {
                book.write(key, value);
            }
        }).andThen(Completable.fromAction(new Action() {
            @Override
            public void run() throws Exception {
                try {
                    updates.onNext(Pair.create(key, value));
                } catch (ClassCastException t) {
                    updates.onError(t);
                }
            }
        })).subscribeOn(scheduler);
    }
that reproduces the old behaviour