/retrofit2-queue-kotlin

The library supports retrofit2 request execution sequentially.

Primary LanguageKotlinApache License 2.0Apache-2.0

retrofit2-queue

The library supports retrofit2 request execution sequentially in Kotlin. Java version is here

Installation

************* Using Gradle *************

Add repository:

repositories {
    jcenter()
}

or

repositories {
    maven {
        url "https://dl.bintray.com/hieupham1993/utilities" 
    }
}

Add this in your app's build.gradle file:

For Gradle < 3.4

compile 'com.hieupt:retrofit2-queue-kotlin:1.0.2'

For Gradle >= 3.4

implementation 'com.hieupt:retrofit2-queue-kotlin:1.0.2'

************* Using Maven *************

<dependency>
  <groupId>com.hieupt</groupId>
  <artifactId>retrofit2-queue-kotlin</artifactId>
  <version>1.0.2</version>
  <type>pom</type>
</dependency>

Usage

Create RetrofitQueue instance

// new instance
val retrofitQueue = RetrofitQueue()
// singleton
val retrofitQueue = RetrofitQueueSingleton.instance

Set number of request can be executed in parallel

retrofitQueue.updateMaxActiveRequest(Int)

Add request to queue

retrofitQueue.addRequest(Call, Callback)
// or
retrofitQueue.addRequestToFrontQueue(Call, Callback)

Execute a request immediately

retrofitQueue.requestNow(Call, Callback)

Cancel a request

// cancel or remove from pending queue a specific request
retrofitQueue.cancel(Call)

Clear pending requests

// clear pending queue
retrofitQueue.clearQueue()