Skip to content

Single fromCallable implementation #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
klemzy opened this issue Feb 6, 2016 · 4 comments
Closed

Single fromCallable implementation #3676

klemzy opened this issue Feb 6, 2016 · 4 comments
Labels

Comments

@klemzy
Copy link

klemzy commented Feb 6, 2016

Hi,

I have noticed that implementation of fromCallable on a Single is:

return create(new OnSubscribe<T>() {
    @Override
    public void call(SingleSubscriber<? super T> singleSubscriber) {
        final T value;
        try {
            value = func.call();
        } catch (Throwable t) {
            Exceptions.throwIfFatal(t);
            singleSubscriber.onError(t);
            return;
        }
        singleSubscriber.onSuccess(value);
    }
});

Is this for some specific reason? Because it could be replaced with:

return new Single<T>(new OnSubscribeFromCallable<>(func));

similarly as from implementation on Single.

@akarnokd
Copy link
Member

akarnokd commented Feb 6, 2016

When the design of Single happened, the focus was too much on reusing Observable's ˙OperatorXXX` classes which added an unnecessary layer of indicrection. I wish it could be remodelled like it is in 2.x so it isn't such a mix of the two worlds.

@klemzy
Copy link
Author

klemzy commented Feb 6, 2016

Thanks for a prompt reply. I understand. So reusing Observable method, converting Single to observable and using Obserable's Operators is discouraged? Actually I am working on this feature #3548 and of the solutions I see it is using Observable's operators and methods.

@akarnokd
Copy link
Member

akarnokd commented Feb 6, 2016

I wouldn't bother reimplementing them from Single but make the Single.retryWhen() just toObservable().retryWhen().toSingle()

@klemzy
Copy link
Author

klemzy commented Feb 8, 2016

Got it. Thanks!

@akarnokd akarnokd closed this as completed Feb 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants