Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 2.1 KB

README.md

File metadata and controls

64 lines (49 loc) · 2.1 KB

RxJava3 Adapter

An Adapter for adapting RxJava 3.x types.

Available types:

  • Observable<T>, Observable<Response<T>>, and Observable<Result<T>> where T is the body type.
  • Flowable<T>, Flowable<Response<T>> and Flowable<Result<T>> where T is the body type.
  • Single<T>, Single<Response<T>>, and Single<Result<T>> where T is the body type.
  • Maybe<T>, Maybe<Response<T>>, and Maybe<Result<T>> where T is the body type.
  • Completable where response bodies are discarded.

Usage

Add RxJava3CallAdapterFactory as a Call adapter when building your Retrofit instance:

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://example.com/")
    .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
    .build();

Your service methods can now use any of the above types as their return type.

interface MyService {
  @GET("/user")
  Observable<User> getUser();
}

By default all reactive types execute their requests synchronously. There are multiple ways to control the threading on which a request occurs:

  • Call subscribeOn on the returned reactive type with a Scheduler of your choice.
  • Use createAsync() when creating the factory which will use OkHttp's internal thread pool.
  • Use createWithScheduler(Scheduler) to supply a default subscription Scheduler.

Download

Download the latest JAR or grab via Maven:

<dependency>
  <groupId>com.squareup.retrofit2</groupId>
  <artifactId>adapter-rxjava3</artifactId>
  <version>latest.version</version>
</dependency>

or Gradle:

implementation 'com.squareup.retrofit2:adapter-rxjava3:latest.version'

Snapshots of the development version are available in Sonatype's snapshots repository.