Skip to content

Latest commit

 

History

History
 
 

rxjava3

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

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, create() will produce reactive types which execute their HTTP requests asynchronously on a background thread. There are two other ways to control the threading on which a request occurs:

  • Use createSynchronous() and call subscribeOn on the returned reactive type with a Scheduler of your choice.
  • 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.