RxDataStore

class RxDataStore<T : Any> : Disposable


A DataStore that supports RxJava operations on DataStore.

Summary

Public functions

Flowable<T>

Gets a reactivex.Flowable of the data from DataStore.

open Unit

Dispose of the DataStore.

open Boolean

Returns whether this DataStore is closed

Completable

Returns a completable that completes when the DataStore is completed.

Single<T>

See DataStore.updateData

Public functions

data

Added in 1.0.0
@ExperimentalCoroutinesApi
fun data(): Flowable<T>

Gets a reactivex.Flowable of the data from DataStore. See 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
Flowable<T>

a flow representing the current state of the data

dispose

Added in 1.0.0
open fun dispose(): Unit

Dispose of the DataStore. Wait for the Completable returned by shutdownComplete to confirm that the DataStore has been shut down.

isDisposed

Added in 1.0.0
open fun isDisposed(): Boolean

Returns whether this DataStore is closed

shutdownComplete

Added in 1.0.0
fun shutdownComplete(): Completable

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
@ExperimentalCoroutinesApi
fun updateDataAsync(transform: Function<T, Single<T>>): Single<T>

See DataStore.updateData

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 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
Single<T>

the snapshot returned by the transform

Throws
kotlin.Exception

when thrown by the transform function