# RxDataStore

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

*** ** * ** ***


```
public final class RxDataStore<T extends Object> implements Disposable
```

<br />

*** ** * ** ***

A DataStore that supports RxJava operations on DataStore.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#data()()` Gets a reactivex.Flowable of the data from DataStore. |
| `void` | `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#dispose()()` Dispose of the DataStore. |
| `boolean` | `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#isDisposed()()` Returns whether this DataStore is closed |
| `boolean` | `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#isDisposed()()` Returns whether this DataStore is closed |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html` | `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#shutdownComplete()()` Returns a completable that completes when the DataStore is completed. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#updateDataAsync(io.reactivex.functions.Function)( @https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/functions/Function.html<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>> transform )` See `https://developer.android.com/reference/androidx/datastore/core/DataStore#updateData(kotlin.coroutines.SuspendFunction1)` |

## Public methods

### data

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

```
@ExperimentalCoroutinesApi
public final @NonNull Flowable<@NonNull T> data()
```

Gets a reactivex.Flowable of the data from DataStore. See `https://developer.android.com/reference/androidx/datastore/core/DataStore#data()` for more information.

Provides efficient, cached (when possible) access to the latest durably persisted state. The flow will always either emit a value or throw an exception encountered when attempting to read from disk. If an exception is encountered, collecting again will attempt to read the data again.

Do not layer a cache on top of this API: it will be be impossible to guarantee consistency. Instead, use data.first() to access a single snapshot.

The Flowable will complete with an IOException when an exception is encountered when reading data.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | a flow representing the current state of the data |

### dispose

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

```
public void dispose()
```

Dispose of the DataStore. Wait for the Completable returned by `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#shutdownComplete()` to confirm that the DataStore has been shut down.

### isDisposed

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

```
public boolean isDisposed()
```

Returns whether this DataStore is closed

### isDisposed

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

```
public boolean isDisposed()
```

Returns whether this DataStore is closed

### shutdownComplete

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

```
public final @NonNull Completable shutdownComplete()
```

Returns a completable that completes when the DataStore is completed. It is not safe to create a new DataStore with the same file name until this has completed.

### updateDataAsync

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

```
@ExperimentalCoroutinesApi
public final @NonNull Single<@NonNull T> updateDataAsync(
    @NonNull Function<@NonNull T, @NonNull Single<@NonNull T>> transform
)
```

See `https://developer.android.com/reference/androidx/datastore/core/DataStore#updateData(kotlin.coroutines.SuspendFunction1)`

Updates the data transactionally in an atomic read-modify-write operation. All operations are serialized, and the transform itself is a async so it can perform heavy work such as RPCs.

The Single completes when the data has been persisted durably to disk (after which `https://developer.android.com/reference/androidx/datastore/rxjava2/RxDataStore#data()` will reflect the update). If the transform or write to disk fails, the transaction is aborted and the returned Single is completed with the error.

The transform will be run on the scheduler that DataStore was constructed with.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | the snapshot returned by the transform |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-exception/index.html` | when thrown by the transform function |