RetrieverWrapper
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:
// the super class from which the other classes will be inherited
abstract class AbstractClass : RetrieverWrapper {
protected val retrieverScope = CoroutineScope(Dispatchers.Default)
private val retrieverScope = Retriever(retrieverScope)
override fun canRetrieverStart(): Boolean {
return retrieverScope.canStart()
}
override fun suspendRetriever() {
retrieverScope.suspend()
}
override fun restartRetriever() {
retrieverScope.restart()
}
override fun continueToRetrieve(
currentContext: KClass<*>
): Boolean {
return retrieverScope.continueToRetrieve(currentContext)
}
override fun retrieve(
currentContext: KClass<*>,
routine: () -> Unit,
repeatRoutine: Boolean,
refreshDelay: Long
) {
retrieverScope.execute(
currentContext = currentContext,
routine = routine,
repeatRoutine = repeatRoutine,
refreshDelay = delay
)
}
}
// an inherit class example
class ExampleClass : AbstractClass {
fun example() {
retrieve(
currentContext = this::class.java,
routine = {
// your routine
}
)
}
fun example1() {
suspendRetriever()
}
}
Author
N7ghtm4r3 - Tecknobit
See also
Inheritors
Functions
Method used to get whether the retrieverScope can start, so if there aren't other jobs that routine is already executing
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
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
Method used to conditionally 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
Method used to set the current active context where the retrieverScope is executing
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
Method used to conditionally 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