GuavaDataStore


class GuavaDataStore<T : Any>


The class that wraps around DataStore to provide an interface that returns ListenableFutures for DataStore reads and writes.

Summary

Nested types

Builder class for a GuavaDataStore.

Public companion functions

GuavaDataStore<T>
<T : Any> from(dataStore: DataStore<T>, coroutineContext: CoroutineContext)

Wraps a GuavaDataStore around a DataStore.

GuavaDataStore<T>
<T : Any> from(dataStore: DataStore<T>, executor: Executor)

Wraps a GuavaDataStore around a DataStore.

Public functions

ListenableFuture<T>

Returns a ListenableFuture to get the latest persisted data.

ListenableFuture<T>
updateDataAsync(dataTransform: Function<T, T>)

Returns a ListenableFuture to update the data using the provided dataTransform.

Public companion functions

from

Added in 1.2.0-beta01
fun <T : Any> from(
    dataStore: DataStore<T>,
    coroutineContext: CoroutineContext = Dispatchers.IO
): GuavaDataStore<T>

Wraps a GuavaDataStore around a DataStore. This method does not create a new DataStore, so all getDataAsync and updateDataAsync called from the resulting GuavaDataStore will be sequenced by the underlying DataStore. It is thread-safe.

Parameters
dataStore: DataStore<T>

the DataStore used to create GuavaDataStore

coroutineContext: CoroutineContext = Dispatchers.IO

the CoroutineContext used to launch the calls to DataStore. The default value is Dispatchers.IO

Returns
GuavaDataStore<T>

the GuavaDataStore created with the provided parameters

from

Added in 1.2.0-beta01
fun <T : Any> from(dataStore: DataStore<T>, executor: Executor): GuavaDataStore<T>

Wraps a GuavaDataStore around a DataStore. This method does not create a new DataStore, so all getDataAsync and updateDataAsync called from the resulting GuavaDataStore will be sequenced by the underlying DataStore. It is thread-safe.

Parameters
dataStore: DataStore<T>

the DataStore used to create GuavaDataStore

executor: Executor

the Executor used to launch the calls to DataStore.

Returns
GuavaDataStore<T>

the GuavaDataStore created with the provided parameters

Public functions

getDataAsync

Added in 1.2.0-beta01
fun getDataAsync(): ListenableFuture<T>

Returns a ListenableFuture to get the latest persisted data. It is not blocked by any ongoing updates.

updateDataAsync

Added in 1.2.0-beta01
fun updateDataAsync(dataTransform: Function<T, T>): ListenableFuture<T>

Returns a ListenableFuture to update the data using the provided dataTransform. The dataTransform is given the latest persisted data to produce its output, which is then persisted and returned. Concurrent updates are serialized (at most one update running at a time).

Ideally the shape of the Function param would have been a T -> R but we choose to keep it as T -> T to match DataStore.updateData.