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.

Public functions

ListenableFuture<T>

Returns a ListenableFuture to get the latest persisted data.

ListenableFuture<T>
updateDataAsync(transform: (input) -> T)

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

Public companion functions

from

Added in 1.2.0-alpha02
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

Public functions

getDataAsync

Added in 1.2.0-alpha02
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-alpha02
fun updateDataAsync(transform: (input) -> T): ListenableFuture<T>

Returns a ListenableFuture to update the data using the provided transform. The transform 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).