RxDataStore

public final class RxDataStore<T extends Object>


A DataStore that supports RxJava operations on DataStore.

Summary

Public methods

final @ExperimentalCoroutinesApi @NonNull Flowable<@NonNull T>

Gets a reactivex.Flowable of the data from DataStore.

void

Dispose of the DataStore.

boolean

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(
    @NonNull Function<@NonNull T, @NonNull Single<@NonNull T>> transform
)

See DataStore.updateData

Public methods

data

@ExperimentalCoroutinesApi
@NonNull
public final @ExperimentalCoroutinesApi 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.

Returns
@ExperimentalCoroutinesApi Flowable<@NonNull T>

a flow representing the current state of the data

dispose

@NonNull
public void dispose()

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

isDisposed

@NonNull
public boolean isDisposed()

Returns whether this DataStore is closed

shutdownComplete

@NonNull
public final 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

@ExperimentalCoroutinesApi
@NonNull
public final @ExperimentalCoroutinesApi Single<@NonNull T> updateDataAsync(
    @NonNull Function<@NonNull T, @NonNull Single<@NonNull 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.

Returns
@ExperimentalCoroutinesApi Single<@NonNull T>

the snapshot returned by the transform

Throws
kotlin.Exception

when thrown by the transform function