# ListenableFuturePagingSource

Artifact: [androidx.paging:paging-guava](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/ListenableFuturePagingSource.kt+class:androidx.paging.ListenableFuturePagingSource) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- android

  ```
  abstract class ListenableFuturePagingSource<Key : Any, Value : Any> : PagingSource<Key, Value>
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.paging.PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource)\<Key, Value\> ||
|   | ↳ | [androidx.paging.ListenableFuturePagingSource](https://developer.android.com/reference/kotlin/androidx/paging/ListenableFuturePagingSource) |

*** ** * ** ***

`https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html`-based compatibility wrapper around `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`'s suspending APIs.

```kotlin
import androidx.paging.ListenableFuturePagingSource
import androidx.paging.PagingState

class MyListenableFuturePagingSource(
    val myBackend: GuavaBackendService,
    val searchTerm: String,
) : ListenableFuturePagingSource<String, Item>() {
    override fun loadFuture(
        params: LoadParams<String>
    ): ListenableFuture<LoadResult<String, Item>> {
        return myBackend
            .searchUsers(searchTerm = searchTerm, pageKey = params.key)
            .transform<LoadResult<String, Item>>(
                { response ->
                    LoadResult.Page(
                        data = response!!.items,
                        prevKey = response.prev,
                        nextKey = response.next,
                    )
                },
                networkExecutor,
            )
            // Retrofit calls that return the body type throw either IOException for
            // network failures, or HttpException for any non-2xx HTTP status codes.
            // This code reports all errors to the UI, but you can inspect/wrap the
            // exceptions to provide more context.
            .catching(
                IOException::class.java,
                { t: IOException? -> LoadResult.Error(t!!) },
                networkExecutor,
            )
            .catching(
                HttpException::class.java,
                { t: HttpException? -> LoadResult.Error(t!!) },
                networkExecutor,
            )
    }

    override fun getRefreshKey(state: PagingState<String, Item>): String? {
        return state.anchorPosition?.let { state.closestItemToPosition(it)?.id }
    }
}
```

## Summary

| ### Public constructors |
|---|---|
| `<Key : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, Value : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/ListenableFuturePagingSource#ListenableFuturePagingSource()()` | android |

| ### Public functions |
|---|---|---|
| `open suspend https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult<Key, Value>` | `https://developer.android.com/reference/kotlin/androidx/paging/ListenableFuturePagingSource#load(androidx.paging.PagingSource.LoadParams)(params: https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadParams<Key>)` | android |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult<Key, Value>>` | `https://developer.android.com/reference/kotlin/androidx/paging/ListenableFuturePagingSource#loadFuture(androidx.paging.PagingSource.LoadParams)(params: https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadParams<Key>)` Loading API for `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`. | android |

### Inherited functions

From [androidx.paging.PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource) `abstract Key?` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#getRefreshKey(androidx.paging.PagingState)(state: https://developer.android.com/reference/kotlin/androidx/paging/PagingState<Key, Value>)` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()()` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#registerInvalidatedCallback(kotlin.Function0)(onInvalidatedCallback: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#unregisterInvalidatedCallback(kotlin.Function0)(onInvalidatedCallback: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` android

### Inherited properties

From [androidx.paging.PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalid()` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#jumpingSupported()` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#keyReuseSupported()` android

## Public constructors

### ListenableFuturePagingSource

android

```
<Key : Any, Value : Any> ListenableFuturePagingSource()
```

## Public functions

### load

android

```
open suspend fun load(params: PagingSource.LoadParams<Key>): PagingSource.LoadResult<Key, Value>
```

### loadFuture

android Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
abstract fun loadFuture(params: PagingSource.LoadParams<Key>): ListenableFuture<PagingSource.LoadResult<Key, Value>>
```

Loading API for `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`.

Implement this method to trigger your async load (e.g. from database or network).