# GuavaDataStore

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

*** ** * ** ***

<br />

```
class GuavaDataStore<T : Any>
```

<br />

*** ** * ** ***

The class that wraps around `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` to provide an interface that returns `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html`s for DataStore reads and writes.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` Builder class for a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore`. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#from(androidx.datastore.core.DataStore,kotlin.coroutines.CoroutineContext)(dataStore: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>, coroutineContext: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` Wraps a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` around a `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#from(androidx.datastore.core.DataStore,java.util.concurrent.Executor)(dataStore: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Wraps a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` around a `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. |

| ### Public functions |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#getDataAsync()()` Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` to get the latest persisted data. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)(dataTransform: https://developer.android.com/reference/kotlin/androidx/core/util/Function<T, T>)` Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` to update the data using the provided `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)`. |

## Public companion functions

### from

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

```
fun <T : Any> from(
    dataStore: DataStore<T>,
    coroutineContext: CoroutineContext = Dispatchers.IO
): GuavaDataStore<T>
```

Wraps a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` around a `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. This method does not create a new `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`, so all `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#getDataAsync()` and `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)` called from the resulting `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` will be sequenced by the underlying `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. It is thread-safe.

| Parameters |
|---|---|
| `dataStore: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>` | the DataStore used to create GuavaDataStore |
| `coroutineContext: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html = Dispatchers.IO` | the CoroutineContext used to launch the calls to DataStore. The default value is `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | the GuavaDataStore created with the provided parameters |

### from

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

```
fun <T : Any> from(dataStore: DataStore<T>, executor: Executor): GuavaDataStore<T>
```

Wraps a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` around a `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. This method does not create a new `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`, so all `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#getDataAsync()` and `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)` called from the resulting `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore` will be sequenced by the underlying `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. It is thread-safe.

| Parameters |
|---|---|
| `dataStore: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>` | the DataStore used to create GuavaDataStore |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the Executor used to launch the calls to DataStore. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | the GuavaDataStore created with the provided parameters |

## Public functions

### getDataAsync

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

```
fun getDataAsync(): ListenableFuture<T>
```

Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` to get the latest persisted data. It is not blocked by any ongoing updates.

### updateDataAsync

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

```
fun updateDataAsync(dataTransform: Function<T, T>): ListenableFuture<T>
```

Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` to update the data using the provided `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)`. The `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore#updateDataAsync(androidx.core.util.Function)` is given the latest persisted data to produce its output, which is then persisted and returned. Concurrent updates are serialized (at most one update running at a time).

Ideally the shape of the `https://developer.android.com/reference/kotlin/androidx/core/util/Function` param would have been a `T -> R` but we choose to keep it as `T -> T` to match `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore#updateData(kotlin.coroutines.SuspendFunction1)`.