Retriever

class Retriever(val retrieverScope: CoroutineScope)

The Retriever handles that repetitive retrieving routines and execute them in background by the retrieverScope

Author

N7ghtm4r3 - Tecknobit

Parameters

retrieverScope

The coroutine used to execute the retrieving routines

Constructors

Link copied to clipboard
constructor(retrieverScope: CoroutineScope)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

The RetrieverWrapper interface is useful for wrapping and facilitating operation with the Retriever, so the inheriting classes will invoke just the wrapper methods for a clean readability of the code, for example:

Link copied to clipboard
private data class RetrievingRoutine(    val currentContext: KClass<*>,     val routine: suspend () -> Unit,     val repeatRoutine: Boolean = true,     val refreshDelay: Long = 1000)

The RetrievingRoutine data class is useful to memorize the last routine executed by the execute method

Properties

Link copied to clipboard
private var isRefreshing: Boolean

isRefreshing whether the retrieverScope is already refreshing

Link copied to clipboard

lastRoutineExecuted the last routine executed by the execute method must re-launched after the suspend method has been invoked

Link copied to clipboard
private val retrieverScope: CoroutineScope

Functions

Link copied to clipboard

Method used to get whether the retrieverScope can start, so if there aren't other jobs that routine is already executing

Link copied to clipboard
fun continueToRetrieve(currentContext: KClass<*>): Boolean

Method used to check if the retrieverScope can continue to refresh or need to be stopped, this for example when the UI displayed changes and the requests to refresh the UI data also changes

Link copied to clipboard
fun execute(currentContext: KClass<*>, routine: suspend () -> Unit, repeatRoutine: Boolean = true, refreshDelay: Long = 1000)

Method used to execute the refresh routine designed

Link copied to clipboard
fun restart()

Method used to restart the current retrieverScope after other requests has been executed, the isRefreshing instance will be set as true to deny the restart of the routine after executing the other requests

Link copied to clipboard
fun suspend()

Method used to suspend the current retrieverScope to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests