-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Fix for RxJava 0.18.+ #468
Conversation
@Override | ||
public Subscription schedule(final Action0 action) { | ||
if (innerSubscription.isUnsubscribed()) { | ||
// don't schedule, we are unsubscribed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize + end with a period. Comments should be sentences (or at least punctuated like them).
We can't force, but we can add an API for it and deprecate the old one.
I'd prefer not to do this. If you have a pool of 3 threads and make 10 requests you want to see the queuing behavior that the normal app would exhibit.
There's an
Agree. |
Unless you feel it's necessary for this issue? I will leave that for another PR.
Yeah I started adding to
I thought that might be the case, I'll leave as-is then. |
@jhump @dragonsinth you might be interested in this. |
Made changes as per feedback. |
// I would potentially force an API change to make sure this is always an | ||
// ExecutorService. | ||
s = Subscriptions.empty(); | ||
executor.execute(getActionRunnable(action, sf)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just use new FutureTask<Void>(getActionRunnable(action, sf), null)
.
Made changes as per @jhump. Didn't Realise I could do that (guess I should of checked what @JakeWharton latest change would negate the need to move towards needing an Might be worth @benjchristensen checking it over, to see if I have missed anything. |
import rx.subscriptions.Subscriptions; | ||
|
||
/** | ||
* Indirection to avoid VerifyError if RxJava isn't present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer useful. Either drop it altogether or change it to something like "Utilities for supporting RxJava Observables".
The reason why I considered trying to put event loops on top of an Keep this in mind while adding support for If someone wants to tackle an Hope this provides some context on this breaking change. As for how many more breaking changes to expect ... theoretically there should not be any more significant ones as we are near the end of the roadmap to 1.0: ReactiveX/RxJava#1001 |
throw new RuntimeException(e); | ||
} | ||
} | ||
}).subscribeOn(scheduler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the only use of Scheduler
within Retrofit, then a multi-threaded Executor
is fine, since it will only ever schedule a single action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. We internalize scheduling for now since RxJava support was kind-of shoved in. In a future world, Retrofit will have a leaner core that an RxJava shim can be built upon where the library doesn't own scheduling at all.
So based off of @benjchristensen comments; Implementing the executor into This also allows the user to define the We do ignore the passed in From what I have understood, I hope that makes sense? |
When an operator requires concurrency (such as The callback via This should not be a problem though, as the use of Rx is supposed to be non-blocking. If someone does IO in a callback (such as in a If you do not want the callbacks running on your thread pool, then you would use executor within |
Yeah that co-1insides with what I understood. I'll amend this pr and add some tests so anyone looking at retrofit will
|
Great. And sorry about the volatility during the 0.x versions! We are very close to stabilizing on 1.0. |
Done a bit of a round trip here, but I'm much happier with this implementation now. Hope you guys agree? I might of over engineered the Other than that, removal of the |
} | ||
@Override public void call(final Subscriber<? super Object> subscriber) { | ||
if (subscriber.isUnsubscribed()) return; | ||
httpExecutor.execute(new Runnable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to support cancelation, you can capture the Future
from this and register it with the Subscriber
.
For example:
subscriber.add(Subscriptions.from(future));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is the MockRestAdapter
so it probably doesn't matter ...
The |
Thanks for the advice, Ben! |
Are you guys happy with this? Let me know if not. |
@benjchristensen Thanks for all the help! @chrisjenx I'll take a closer look tomorrow morning but it's looking good. |
Squashed and merged to |
Needs review.
This adds a
RetrofitScheduler
which is loosely based on the NewThreadScheduler but alows us to provide the Executor.I was not sure the direction the Square guys want to go with this. So apologies if it does not follow your guidelines, I'll happily change/move stuff.
I moved the
RetrofitScheduler
into package safeSchedulers
class to hide and share the API in theRestAdapter
andMockRestAdapter
.Few questions still outstanding:
Schedulers
the right place for theRetrofitScheduler
? Not sure if there would ever be more than one?RetrofitScheduler
does a type check forExecutorService
but thats not guaranteed. Should we forceExecutorService
?MockRetrofitScheduler
seems to do waiting of its own, Is there a reason we need to use thehttpExecutor
or could we just userx.Schedulers.newThread()
?schedule
method in theRetrofitScheduler
, I feel that any timing based observable work should not be passed to the Retrofit ThreadPool.I was toying with a way to allow users to pass through a
Scheduler
to Retrofit, but I think that would be unnecessary as we can just call retrofit service synchronously.