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 |
|---|
class GuavaDataStore.Builder<T : Any>Builder class for a |
Public companion functions |
|
|---|---|
GuavaDataStore<T> |
<T : Any> from(dataStore: DataStore<T>, coroutineContext: CoroutineContext)Wraps a |
GuavaDataStore<T> |
Wraps a |
Public functions |
|
|---|---|
ListenableFuture<T> |
Returns a |
ListenableFuture<T> |
updateDataAsync(dataTransform: Function<T, T>)Returns a |
Public companion functions
from
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 |
| Returns | |
|---|---|
GuavaDataStore<T> |
the GuavaDataStore created with the provided parameters |
from
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
fun getDataAsync(): ListenableFuture<T>
Returns a ListenableFuture to get the latest persisted data. It is not blocked by any ongoing updates.
updateDataAsync
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.