From 16eb18b07e6bb285c0e05105b30ba9ffede36462 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 4 Jul 2024 14:39:28 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../java/com/tangem/pagination/BatchAction.kt | 24 ++-- .../{FetchResult.kt => BatchFetchResult.kt} | 16 +-- .../com/tangem/pagination/BatchListSource.kt | 128 +++++++++--------- .../com/tangem/pagination/BatchListState.kt | 5 +- .../tangem/pagination/BatchUpdateFetcher.kt | 10 +- .../tangem/pagination/BatchUpdateResult.kt | 27 ++++ .../com/tangem/pagination/BatchingConfig.kt | 12 -- .../com/tangem/pagination/BatchingContext.kt | 6 +- .../tangem/pagination/FetchUpdateResult.kt | 36 ----- .../com/tangem/pagination/PaginationStatus.kt | 29 ++-- .../tangem/pagination/fetcher/BatchFetcher.kt | 12 +- .../fetcher/LimitOffsetBatchFetcher.kt | 25 ++-- 12 files changed, 147 insertions(+), 183 deletions(-) rename core/pagination/src/main/java/com/tangem/pagination/{FetchResult.kt => BatchFetchResult.kt} (55%) create mode 100644 core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt delete mode 100644 core/pagination/src/main/java/com/tangem/pagination/BatchingConfig.kt delete mode 100644 core/pagination/src/main/java/com/tangem/pagination/FetchUpdateResult.kt diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt index 813cbe6ba9..20d95b63aa 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt @@ -3,41 +3,41 @@ package com.tangem.pagination /** * Action that can be dispatched to [BatchListSource]. * - * @param TRequest type of the request to load batches. + * @param TRequestParams type of the request params to load batches. * @param TKey type of the key of the batch. * @param TUpdate type of the update request. */ -sealed class BatchAction { +sealed class BatchAction { /** * Action to load the first batch. * - * @param request request to load the first batch. + * @param requestParams request params to load the first batch. */ - data class Reload( - val request: TRequest, - ) : BatchAction() + data class Reload( + val requestParams: TRequestParams, + ) : BatchAction() /** * Action to load the next batch. * - * @param request request to load the next batch with new request. + * @param requestParams request params to load the next batch with new request. * If null, the last request will be used. * Will be saved in the state and used for future LoadMore actions with request = null. */ - data class LoadMore( - val request: TRequest? = null, - ) : BatchAction() + data class LoadMore( + val requestParams: TRequestParams? = null, + ) : BatchAction() /** * Action to update the batch. * * @param keys keys of the batches to update. - * @param request request to update the batches. + * @param updateRequest request to update the batches. */ class UpdateBatches( val keys: Set, - val request: TUpdate, + val updateRequest: TUpdate, ) : BatchAction() /** diff --git a/core/pagination/src/main/java/com/tangem/pagination/FetchResult.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt similarity index 55% rename from core/pagination/src/main/java/com/tangem/pagination/FetchResult.kt rename to core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt index d72c42ac1d..a247310b9c 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/FetchResult.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt @@ -5,9 +5,8 @@ package com.tangem.pagination * Used in [BatchListState]. * * @param TData type of the data. - * @param TError type of the error. */ -sealed class FetchResult { +sealed class BatchFetchResult { /** * Represents a successful result of a batch fetch request. @@ -18,21 +17,14 @@ sealed class FetchResult { data class Success( val data: TData, val last: Boolean = false, - ) : FetchResult() + ) : BatchFetchResult() /** * Represents an error result of a batch fetch request. - * - * @param error error that occurred during the request. - */ - data class Error(val error: TError) : FetchResult() - - /** - * Represents an unknown error result of a batch fetch request. - * Used for unexpected exceptions that occurred in fetch method in BatchFetcher. + * Also used for unexpected exceptions that occurred in fetch method in BatchFetcher. * * @param throwable throwable that occurred during the request. * @see com.tangem.pagination.fetcher.BatchFetcher */ - class UnknownError(val throwable: Throwable) : FetchResult() + class Error(val throwable: Throwable) : BatchFetchResult() } \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt index 0c6c05bd57..bd521c6f71 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt @@ -11,19 +11,18 @@ import kotlinx.coroutines.flow.* * @param TKey Type of the key that identifies a batch. * @param TData Type of the data in the batch. Generally, it' a list of items. * @param TUpdate Type of the update request. - * @param TError Type of the error that can occur during fetching or updating. * @property state State of the paginated data. * @property updateResults Flow of results of update requests. */ -interface BatchListSource { - val state: StateFlow> - val updateResults: SharedFlow>> +interface BatchListSource { + val state: StateFlow> + val updateResults: SharedFlow>> } /** * Creates a new [BatchListSource] with the provided configuration. * - * @param ioDispatcher Dispatcher for IO operations. + * @param fetchDispatcher Dispatcher for fetch operations. * @param context Context for batching. * @param generateNewKey Function to generate a new key for a batch. * @param batchFetcher Function to fetch a batch of data. @@ -31,18 +30,18 @@ interface BatchListSource { * @return New instance of [BatchListSource]. */ @Suppress("FunctionNaming") -fun BatchListSource( - ioDispatcher: CoroutineDispatcher = Dispatchers.IO, +fun BatchListSource( + fetchDispatcher: CoroutineDispatcher = Dispatchers.IO, context: BatchingContext, generateNewKey: suspend (List) -> TKey, - batchFetcher: BatchFetcher, -): BatchListSource = - BatchListSourceImpl(ioDispatcher, context, generateNewKey, batchFetcher, null) + batchFetcher: BatchFetcher, +): BatchListSource = + DefaultBatchListSource(fetchDispatcher, context, generateNewKey, batchFetcher, null) /** * Creates a new [BatchListSource] with the provided configuration. * - * @param ioDispatcher Dispatcher for IO operations. + * @param fetchDispatcher Dispatcher for fetch operations. * @param context Context for batching. * @param generateNewKey Function to generate a new key for a batch. * @param batchFetcher Function to fetch a batch of data. @@ -51,25 +50,25 @@ fun BatchListSource( * @return New instance of [BatchListSource]. */ @Suppress("FunctionNaming") -fun BatchListSource( - ioDispatcher: CoroutineDispatcher = Dispatchers.IO, - context: BatchingContext, +fun BatchListSource( + fetchDispatcher: CoroutineDispatcher = Dispatchers.IO, + context: BatchingContext, generateNewKey: suspend (List) -> TKey, - batchFetcher: BatchFetcher, - updateFetcher: BatchUpdateFetcher, -): BatchListSource = - BatchListSourceImpl(ioDispatcher, context, generateNewKey, batchFetcher, updateFetcher) + batchFetcher: BatchFetcher, + updateFetcher: BatchUpdateFetcher, +): BatchListSource = + DefaultBatchListSource(fetchDispatcher, context, generateNewKey, batchFetcher, updateFetcher) -private class BatchListSourceImpl( - private val ioDispatcher: CoroutineDispatcher, - private val context: BatchingContext, +private class DefaultBatchListSource( + private val fetchDispatcher: CoroutineDispatcher, + private val context: BatchingContext, private val generateNewKey: suspend (List) -> TKey, - private val batchFetcher: BatchFetcher, - private val updateFetcher: BatchUpdateFetcher? = null, -) : BatchListSource { + private val batchFetcher: BatchFetcher, + private val updateFetcher: BatchUpdateFetcher? = null, +) : BatchListSource { - override val state = MutableStateFlow(BatchListState(emptyList(), PaginationStatus.None)) - override val updateResults = MutableSharedFlow>>( + override val state = MutableStateFlow(BatchListState(emptyList(), PaginationStatus.None)) + override val updateResults = MutableSharedFlow>>( extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST, ) @@ -79,7 +78,7 @@ private class BatchListSourceImpl( private val waitingUpdateJobs = MutableStateFlow, Job>>>(emptyList()) - private val lastRequestResult = MutableStateFlow?>(null) + private val lastRequestResult = MutableStateFlow?>(null) private var reloadActionJob: Job? = null private var loadMoreActionJob: Job? = null @@ -105,14 +104,14 @@ private class BatchListSourceImpl( } } - private fun collectActions(action: BatchAction) { + private fun collectActions(action: BatchAction) { when (action) { is BatchAction.Reload -> { // Stop all tasks loadMoreActionJob?.cancel() reloadActionJob?.cancel() stopAllUpdates() - reloadActionJob = scope.launch(ioDispatcher) { + reloadActionJob = scope.launch(fetchDispatcher) { reloadTask(action) } } @@ -121,7 +120,7 @@ private class BatchListSourceImpl( return } - loadMoreActionJob = scope.launch(ioDispatcher) { + loadMoreActionJob = scope.launch(fetchDispatcher) { reloadActionJob?.join() loadMoreTask(action) } @@ -129,7 +128,7 @@ private class BatchListSourceImpl( is BatchAction.UpdateBatches -> { if (updateFetcher == null) return - scope.launch(ioDispatcher) { + scope.launch(fetchDispatcher) { val job = launch(start = CoroutineStart.LAZY) { updateBatchesTask(action) } @@ -172,60 +171,63 @@ private class BatchListSourceImpl( } } - private suspend fun reloadTask(action: BatchAction.Reload) { + private suspend fun reloadTask(action: BatchAction.Reload) { state.value = BatchListState( data = emptyList(), status = PaginationStatus.InitialLoading, ) val res = runCatching { - batchFetcher.fetchFirst(action.request) - }.getOrElse { FetchResult.UnknownError(it) } + batchFetcher.fetchFirst(action.requestParams) + }.getOrElse { BatchFetchResult.Error(it) } - state.value = if (res is FetchResult.Success) { - val key = generateNewKey(listOf()) - val batch = Batch( - key = key, - data = res.data, - ) - BatchListState( - data = listOf(batch), - status = if (res.last) { - PaginationStatus.EndOfPagination - } else { - PaginationStatus.Paginating(res) - }, - ) - } else { - BatchListState( - data = emptyList(), - status = PaginationStatus.InitialLoadingError( - error = (res as? FetchResult.Error)?.error, - ), - ) + state.value = when (res) { + is BatchFetchResult.Success -> { + val key = generateNewKey(listOf()) + val batch = Batch( + key = key, + data = res.data, + ) + BatchListState( + data = listOf(batch), + status = if (res.last) { + PaginationStatus.EndOfPagination + } else { + PaginationStatus.Paginating(res) + }, + ) + } + is BatchFetchResult.Error -> { + BatchListState( + data = emptyList(), + status = PaginationStatus.InitialLoadingError( + throwable = res.throwable, + ), + ) + } } lastRequestResult.value = res } - private suspend fun loadMoreTask(action: BatchAction.LoadMore) { + private suspend fun loadMoreTask(action: BatchAction.LoadMore) { val status = state.value.status if (status !is PaginationStatus.Paginating && status !is PaginationStatus.EndOfPagination) return - if (status is PaginationStatus.EndOfPagination && action.request == null) return + if (status is PaginationStatus.EndOfPagination && action.requestParams == null) return val lastResult = lastRequestResult.value ?: return state.update { it.copy(status = PaginationStatus.NextBatchLoading) } val res = runCatching { - batchFetcher.fetchNext(action.request, lastResult) - }.getOrElse { FetchResult.UnknownError(it) } + batchFetcher.fetchNext(action.requestParams, lastResult) + }.getOrElse { BatchFetchResult.Error(it) } lastRequestResult.value = lastResult state.update { currentState -> - if (res is FetchResult.Success) { + if (res is BatchFetchResult.Success) { val newBatch = Batch( key = generateNewKey(currentState.data.map { it.key }), data = res.data, @@ -255,10 +257,10 @@ private class BatchListSourceImpl( val result = updateFetcher.fetchUpdate( toUpdate = batchesToUpdate, - updateRequest = action.request, + updateRequest = action.updateRequest, ) - if (result is FetchUpdateResult.Success) { + if (result is BatchUpdateResult.Success) { state.update { currentState -> val resMap = result.data.associateBy { it.key } currentState.copy( @@ -269,7 +271,7 @@ private class BatchListSourceImpl( } } - updateResults.emit(action.request to result) + updateResults.emit(action.updateRequest to result) } private fun stopAllUpdates() { diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt index 525458362f..b53ba23dc0 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt @@ -5,14 +5,13 @@ package com.tangem.pagination * * @param TKey type of the key of the batch. * @param TData type of the data. - * @param TError type of the error. * * @property data list of loaded batches. * @property status current status of the pagination. * * @see BatchListSource */ -data class BatchListState( +data class BatchListState( val data: List>, - val status: PaginationStatus, + val status: PaginationStatus, ) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt index 1cf7e10a91..704c416316 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt @@ -6,20 +6,18 @@ package com.tangem.pagination * * @param TKey type of the key. * @param TData type of the data. - * @param TError type of the error. * @param TUpdate type of the update request. */ -interface BatchUpdateFetcher { +fun interface BatchUpdateFetcher { /** * Fetches updates for a batch of data. + * Note that the result batch key as a result of executing the method must be presented in the [toUpdate] list, + * otherwise, updates will not be performed * * @param toUpdate list of batches to update. * @param updateRequest request to update the data. * @return result of the update operation. */ - suspend fun fetchUpdate( - toUpdate: List>, - updateRequest: TUpdate, - ): FetchUpdateResult + suspend fun fetchUpdate(toUpdate: List>, updateRequest: TUpdate): BatchUpdateResult } \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt new file mode 100644 index 0000000000..c2e00fad9c --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt @@ -0,0 +1,27 @@ +package com.tangem.pagination + +/** + * Represents the result of a batch fetch operation. + * Used in [BatchListState] and [BatchUpdateFetcher]. + * + * @param TKey type of the key. + * @param TData type of the data. + */ +sealed class BatchUpdateResult { + + /** + * Represents a successful result of a batch update operation. + * + * @param data fetched data. + */ + data class Success( + val data: List>, + ) : BatchUpdateResult() + + /** + * Represents an error result of a batch update operation. + * + * @param error error that occurred during the operation. + */ + class Error(val throwable: Throwable) : BatchUpdateResult() +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchingConfig.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchingConfig.kt deleted file mode 100644 index 8789d11405..0000000000 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchingConfig.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.pagination - -/** - * Configuration for batching. - * - * @param batchSize size of the batch. - * @param prefetchDistance number of items to fetch for the first batch. - */ -data class BatchingConfig( - val batchSize: Int, - val prefetchDistance: Int = batchSize, -) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt index 37b6bd2c73..fb9672d365 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow /** * Context for working with [BatchListSource]. * - * @param TRequest type of the request. + * @param TRequestParams type of the request. * @param TKey type of the key. * @param TUpdate type of the update request. * @@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.Flow * * @see BatchListSource */ -class BatchingContext( - val actionsFlow: Flow>, +class BatchingContext( + val actionsFlow: Flow>, val coroutineScope: CoroutineScope, ) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/FetchUpdateResult.kt b/core/pagination/src/main/java/com/tangem/pagination/FetchUpdateResult.kt deleted file mode 100644 index d575044a1f..0000000000 --- a/core/pagination/src/main/java/com/tangem/pagination/FetchUpdateResult.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.tangem.pagination - -/** - * Represents the result of a batch fetch operation. - * Used in [BatchListState] and [BatchUpdateFetcher]. - * - * @param TKey type of the key. - * @param TData type of the data. - * @param TError type of the error. - */ -sealed class FetchUpdateResult { - - /** - * Represents a successful result of a batch update operation. - * - * @param data fetched data. - */ - data class Success( - val data: List>, - ) : FetchUpdateResult() - - /** - * Represents an error result of a batch update operation. - * - * @param error error that occurred during the operation. - */ - data class Error(val error: TError) : FetchUpdateResult() - - /** - * Represents an unknown error result of a batch update operation. - * Used for unexpected exceptions that occurred in `fetchUpdate` method in [BatchUpdateFetcher]. - * - * @param throwable throwable that occurred during the operation. - */ - class UnknownError(val throwable: Throwable) : FetchUpdateResult() -} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt b/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt index ec30a2ea1e..5e30875c6a 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt @@ -3,54 +3,53 @@ package com.tangem.pagination /** * Status of the pagination. * - * @param T type of the data. - * @param E type of the error. + * @param TData type of the data. * * @see BatchListState */ -sealed class PaginationStatus { +sealed class PaginationStatus { /** * Represents that there is no data. Used when the list of batches is empty. * The initial state of the pagination. */ - data object None : PaginationStatus() + data object None : PaginationStatus() /** * Represents that the batch is loading for the first time. * Used when the pagination is empty and the first batch is being loaded. */ - data object InitialLoading : PaginationStatus() + data object InitialLoading : PaginationStatus() /** * Represents that the first batch was loaded with an error. * * @param error error that occurred during the initial loading. */ - data class InitialLoadingError( - val error: E?, - ) : PaginationStatus() + data class InitialLoadingError( + val throwable: Throwable, + ) : PaginationStatus() /** * Represents that the last batch was loaded and * the source is ready to load the next one or reload previous if [lastResult] is an error. - * For the first batch, [lastResult] is always [FetchResult.Success] + * For the first batch, [lastResult] is always [BatchFetchResult.Success] * * @param lastResult result of the last batch fetch. */ - data class Paginating( - val lastResult: FetchResult, - ) : PaginationStatus() + data class Paginating( + val lastResult: BatchFetchResult, + ) : PaginationStatus() /** * Represents that the next batch is loading. * Used when the next batch is being loaded. */ - data object NextBatchLoading : PaginationStatus() + data object NextBatchLoading : PaginationStatus() /** * Represents that the source has no more batches to load. - * The next [BatchAction.LoadMore] with [BatchAction.LoadMore.request] = null will be ignored. + * The next [BatchAction.LoadMore] with [BatchAction.LoadMore.requestParams] = null will be ignored. */ - data object EndOfPagination : PaginationStatus() + data object EndOfPagination : PaginationStatus() } \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt index 2d9e50832e..98358257b5 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt @@ -1,6 +1,6 @@ package com.tangem.pagination.fetcher -import com.tangem.pagination.FetchResult +import com.tangem.pagination.BatchFetchResult import com.tangem.pagination.BatchListState /** @@ -8,11 +8,10 @@ import com.tangem.pagination.BatchListState * * @param TRequest type of the request. * @param TData type of the data. - * @param TError type of the error. * * @see BatchListState */ -interface BatchFetcher { +interface BatchFetcher { /** * Fetches the first batch of data. @@ -20,7 +19,7 @@ interface BatchFetcher { * @param request initial request. Will be saved to be used in [fetchNext] requests. * @return result of the fetch operation. */ - suspend fun fetchFirst(request: TRequest): FetchResult + suspend fun fetchFirst(request: TRequest): BatchFetchResult /** * Fetches the next batch of data. @@ -30,8 +29,5 @@ interface BatchFetcher { * @param lastResult result of the last fetch operation. * @return result of the fetch operation. */ - suspend fun fetchNext( - overrideRequest: TRequest?, - lastResult: FetchResult, - ): FetchResult + suspend fun fetchNext(overrideRequest: TRequest?, lastResult: BatchFetchResult): BatchFetchResult } \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt index 858411b6a6..6a321a61e9 100644 --- a/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt +++ b/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt @@ -1,25 +1,24 @@ package com.tangem.pagination.fetcher -import com.tangem.pagination.FetchResult +import com.tangem.pagination.BatchFetchResult import com.tangem.pagination.exception.EndOfPaginationException import kotlinx.coroutines.flow.MutableStateFlow /** * Fetcher that uses limit and offset to fetch data. * - * @param TRequest type of the request. + * @param TRequestParams type of the request params. * @param TData type of the data. - * @param TError type of the error. * * @property prefetchDistance number of items to fetch for the first batch. * @property batchSize size of the batch. * @property fetch function that fetches the data. */ -class LimitOffsetBatchFetcher( +class LimitOffsetBatchFetcher( private val prefetchDistance: Int, private val batchSize: Int, - private val fetch: (request: Request) -> FetchResult, -) : BatchFetcher { + private val fetch: (request: Request) -> BatchFetchResult, +) : BatchFetcher { data class Request( val limit: Int, @@ -27,9 +26,9 @@ class LimitOffsetBatchFetcher( val request: TRequest, ) - private val lastRequest = MutableStateFlow?>(null) + private val lastRequest = MutableStateFlow?>(null) - override suspend fun fetchFirst(request: TRequest): FetchResult { + override suspend fun fetchFirst(request: TRequestParams): BatchFetchResult { val req = Request( offset = 0, limit = prefetchDistance, @@ -42,15 +41,15 @@ class LimitOffsetBatchFetcher( } override suspend fun fetchNext( - overrideRequest: TRequest?, - lastResult: FetchResult, - ): FetchResult { + overrideRequest: TRequestParams?, + lastResult: BatchFetchResult, + ): BatchFetchResult { val last = lastRequest.value requireNotNull(last) - val req = if (lastResult is FetchResult.Success) { + val req = if (lastResult is BatchFetchResult.Success) { if (lastResult.last && overrideRequest == null) { - return FetchResult.UnknownError(EndOfPaginationException()) + return BatchFetchResult.Error(EndOfPaginationException()) } Request(