GuavaDataStore
public final class GuavaDataStore<T extends Object>
The class that wraps around DataStore to provide an interface that returns ListenableFutures for DataStore reads and writes.
Summary
Nested types |
|---|
public final class GuavaDataStore.Builder<T extends Object>Builder class for a |
Public methods |
|
|---|---|
static final @NonNull GuavaDataStore<@NonNull T> |
<T extends Object> from(Wraps a |
static final @NonNull GuavaDataStore<@NonNull T> |
Wraps a |
final @NonNull ListenableFuture<@NonNull T> |
Returns a |
final @NonNull ListenableFuture<@NonNull T> |
updateDataAsync(@NonNull Function<@NonNull T, @NonNull T> dataTransform)Returns a |
Public methods
from
public static final @NonNull GuavaDataStore<@NonNull T> <T extends Object> from(
@NonNull DataStore<@NonNull T> dataStore,
@NonNull CoroutineContext coroutineContext
)
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 | |
|---|---|
@NonNull DataStore<@NonNull T> dataStore |
the DataStore used to create GuavaDataStore |
@NonNull CoroutineContext coroutineContext |
the CoroutineContext used to launch the calls to DataStore. The default value is |
| Returns | |
|---|---|
@NonNull GuavaDataStore<@NonNull T> |
the GuavaDataStore created with the provided parameters |
from
public static final @NonNull GuavaDataStore<@NonNull T> <T extends Object> from(
@NonNull DataStore<@NonNull T> dataStore,
@NonNull Executor executor
)
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 | |
|---|---|
@NonNull DataStore<@NonNull T> dataStore |
the DataStore used to create GuavaDataStore |
@NonNull Executor executor |
the Executor used to launch the calls to DataStore. |
| Returns | |
|---|---|
@NonNull GuavaDataStore<@NonNull T> |
the GuavaDataStore created with the provided parameters |
getDataAsync
public final @NonNull ListenableFuture<@NonNull T> getDataAsync()
Returns a ListenableFuture to get the latest persisted data. It is not blocked by any ongoing updates.
updateDataAsync
public final @NonNull ListenableFuture<@NonNull T> updateDataAsync(@NonNull Function<@NonNull T, @NonNull T> dataTransform)
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.