Reputation: 73
what is the difference between RxJava2CallAdapterFactory.create()
& RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())
? Which one should prefer?
Upvotes: 1
Views: 261
Reputation: 2076
Difference from the source code
Both methods returns an instance of synchronous observable, but the create()
method has no schedulers to operate on by default and the createWithSchedulers(Scheduler scheduler)
as name suggests, operates on the respective scheduler by default which you mention in method, as per your example it will be Scheduler.io()
.
Which one you should use?
Now this will depend on you, the APIs you directly want to return instance in Schedulers.io()
or other Schedulers by default then you use the one with schedulers, else you can use the create()
method and can declare schedulers while getting response every time.
Note: I personally use create()
method as I sometimes mention some other Schedulers.newThread()
and/or Schedulers.computation()
Upvotes: 0
Reputation: 3253
If you pass Scheduler
to RxJava2CallAdapterFactory, it will add subscribeOn(scheduler)
to each network request you are making. It is just a convenience method.
Upvotes: 1