public final class RxDataStore<T extends Object>

A DataStore that supports RxJava operations on DataStore.


Public methods

final @ExperimentalCoroutinesApi @NonNull Flowable<@NonNull T>

Gets a reactivex.Flowable of the data from DataStore.


Dispose of the DataStore.


Returns whether this DataStore is closed

final @NonNull Completable

Returns a completable that completes when the DataStore is completed.

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

See DataStore.updateData

Public methods


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

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.

@NonNull Flowable<@NonNull T>

a flow representing the current state of the data


public void dispose()

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


public boolean isDisposed()

Returns whether this DataStore is closed


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.


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

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.

@NonNull Single<@NonNull T>

the snapshot returned by the transform


when thrown by the transform function