StorageConnection
public interface StorageConnection<T extends Object> extends Closeable
StorageConnection provides a way to read and write a particular type Storage objects.
Summary
Public methods |
|
|---|---|
abstract @NonNull InterProcessCoordinator |
Provides a coordinator to guarantee data consistency across multiple threads and processes. |
abstract @NonNull R |
<R extends Object> readScope(Creates a scope for reading to allow storage reads, and will try to obtain a read lock. |
abstract void |
writeScope(Creates a write scope that guaranteed to only have one single writer, ensuring also that any reads within this scope have the most current data. |
Extension functions |
|
|---|---|
default final @NonNull T |
<T extends Object> StorageConnectionKt.readData( |
default final void |
<T extends Object> StorageConnectionKt.writeData( |
Inherited methods |
||
|---|---|---|
|
Public methods
getCoordinator
abstract @NonNull InterProcessCoordinator getCoordinator()
Provides a coordinator to guarantee data consistency across multiple threads and processes.
readScope
abstract @NonNull R <R extends Object> readScope(
@NonNull SuspendFunction2<@NonNull ReadScope<@NonNull T>, @NonNull Boolean, @NonNull R> block
)
Creates a scope for reading to allow storage reads, and will try to obtain a read lock.
| Parameters | |
|---|---|
@NonNull SuspendFunction2<@NonNull ReadScope<@NonNull T>, @NonNull Boolean, @NonNull R> block |
The block of code that is performed within this scope. Block will receive |
| Throws | |
|---|---|
androidx.datastore.core.IOException |
when there is an unrecoverable exception in reading. |
writeScope
abstract void writeScope(
@NonNull SuspendFunction1<@NonNull WriteScope<@NonNull T>, Unit> block
)
Creates a write scope that guaranteed to only have one single writer, ensuring also that any reads within this scope have the most current data.
| Throws | |
|---|---|
androidx.datastore.core.IOException |
when there is an unrecoverable exception in writing. |
Extension functions
StorageConnectionKt.readData
default final @NonNull T <T extends Object> StorageConnectionKt.readData(
@NonNull StorageConnection<@NonNull T> receiver
)
StorageConnectionKt.writeData
default final void <T extends Object> StorageConnectionKt.writeData(
@NonNull StorageConnection<@NonNull T> receiver,
@NonNull T value
)