# androidx.datastore.rxjava3

# androidx.datastore.rxjava3

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/datastore/rxjava3/package-summary "View this page in Java")

## Interfaces

|----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------|
| [RxDataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxDataMigration)                           | Interface for migrations to DataStore.  |
| [RxSharedPreferencesMigration](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxSharedPreferencesMigration) | Client implemented migration interface. |

## Classes

|------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [RxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxDataStore)                                                 | A DataStore that supports RxJava operations on DataStore.                 |
| [RxDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxDataStoreBuilder)                                   | Builder class for an RxDataStore that works on a single process.          |
| [RxSharedPreferencesMigrationBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxSharedPreferencesMigrationBuilder) | RxSharedPreferencesMigrationBuilder for the RxSharedPreferencesMigration. |

## Top-level functions summary

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ReadOnlyProperty](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.properties/-read-only-property/index.html)`<`[Context](https://developer.android.com/reference/android/content/Context.html)`, `[RxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxDataStore)`<T>>` | `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`> `[rxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/package-summary#rxDataStore(kotlin.String,androidx.datastore.core.Serializer,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.Function1,io.reactivex.rxjava3.core.Scheduler))`(` ` fileName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` serializer: `[Serializer](https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer)`<T>,` ` corruptionHandler: `[ReplaceFileCorruptionHandler](https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler)`<T>?,` ` produceMigrations: (`[Context](https://developer.android.com/reference/android/content/Context.html)`) `->` `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[DataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration)`<T>>,` ` scheduler: `[Scheduler](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html) `)` Creates a property delegate for a single process DataStore. |

## Top-level functions

### rxDataStore

Artifact:[androidx.datastore:datastore-rxjava3](https://developer.android.com/jetpack/androidx/releases/datastore)  
[View Source](https://cs.android.com/search?q=file:androidx/datastore/rxjava3/RxDataStoreDelegate.kt+function:rxDataStore)  

```
fun <T : Any> rxDataStore(
    fileName: String,
    serializer: Serializer<T>,
    corruptionHandler: ReplaceFileCorruptionHandler<T>? = null,
    produceMigrations: (Context) -> List<DataMigration<T>> = { listOf() },
    scheduler: Scheduler = Schedulers.io()
): ReadOnlyProperty<Context, RxDataStore<T>>
```

Creates a property delegate for a single process DataStore. This should only be called once in a file (at the top level), and all usages of the DataStore should use a reference the same Instance. The receiver type for the property delegate must be an instance of[Context](https://developer.android.com/reference/android/content/Context.html).

This should only be used from a single application in a single classloader in a single process.

Example usage:  

```kotlin
val Context.myRxDataStore by rxDataStore("filename", serializer)

class SomeClass(val context: Context) {
   fun update(): Single<Settings> = context.myRxDataStore.updateDataAsync {...}
}
```  

|                                                                                                                                                              Parameters                                                                                                                                                              |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fileName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                                                                                                        | the filename relative to Context.filesDir that DataStore acts on. The File is obtained by calling File(context.filesDir, "datastore/$fileName")). No two instances of DataStore should act on the same file at the same time.                                                                                                                    |
| `serializer: `[Serializer](https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer)`<T>`                                                                                                                                                                                                                   | the Serializer to serialize and deserialize on-disk data to type[T](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/package-summary#rxDataStore(kotlin.String,androidx.datastore.core.Serializer,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.Function1,io.reactivex.rxjava3.core.Scheduler)). |
| `corruptionHandler: `[ReplaceFileCorruptionHandler](https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler)`<T>? = null`                                                                                                                                                       | The corruptionHandler is invoked if DataStore encounters a[androidx.datastore.core.CorruptionException](https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException)when attempting to read data. CorruptionExceptions are thrown by serializers when data can not be de-serialized.                              |
| `produceMigrations: (`[Context](https://developer.android.com/reference/android/content/Context.html)`) `->` `[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[DataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration)`<T>> = { listOf() }` | produce the migrations. The ApplicationContext is passed in to these callbacks as a parameter. DataMigrations are run before any access to data can occur. Each producer and migration may be run more than once whether or not it already succeeded (potentially because another migration failed or a write to disk failed.)                   |
| `scheduler: `[Scheduler](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html)` = Schedulers.io()`                                                                                                                                                                                                        | The scheduler in which IO operations and transform functions will execute.                                                                                                                                                                                                                                                                       |

|                                                                                                                                                      Returns                                                                                                                                                       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [ReadOnlyProperty](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.properties/-read-only-property/index.html)`<`[Context](https://developer.android.com/reference/android/content/Context.html)`, `[RxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava3/RxDataStore)`<T>>` | a property delegate that manages a datastore as a singleton. |