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 GuavaDataStore.

Public methods

static final @NonNull GuavaDataStore<@NonNull T>
<T extends Object> from(
    @NonNull DataStore<@NonNull T> dataStore,
    @NonNull CoroutineContext coroutineContext
)

Wraps a GuavaDataStore around a DataStore.

final @NonNull ListenableFuture<@NonNull T>

Returns a ListenableFuture to get the latest persisted data.

final @NonNull ListenableFuture<@NonNull T>
updateDataAsync(@NonNull Function1<@NonNull input, @NonNull T> transform)

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

Public methods

from

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

Returns
@NonNull GuavaDataStore<@NonNull T>

the GuavaDataStore created with the provided parameters

getDataAsync

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

Added in 1.2.0-alpha02
public final @NonNull ListenableFuture<@NonNull T> updateDataAsync(@NonNull Function1<@NonNull input, @NonNull T> transform)

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).