StorageConnection


interface StorageConnection<T : Any?> : Closeable


StorageConnection provides a way to read and write a particular type of data. StorageConnections are created from Storage objects.

Summary

Public functions

suspend R
<R : Any?> readScope(block: suspend ReadScope<T>.(locked: Boolean) -> R)

Creates a scope for reading to allow storage reads, and will try to obtain a read lock.

suspend Unit
writeScope(block: suspend WriteScope<T>.() -> Unit)

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.

Public properties

InterProcessCoordinator

Provides a coordinator to guarantee data consistency across multiple threads and processes.

Extension functions

suspend T
suspend Unit
<T : Any?> StorageConnection<T>.writeData(value: T)

Inherited functions

From androidx.datastore.core.Closeable
Unit

Closes the specified resource.

Public functions

readScope

suspend fun <R : Any?> readScope(block: suspend ReadScope<T>.(locked: Boolean) -> R): R

Creates a scope for reading to allow storage reads, and will try to obtain a read lock.

Parameters
block: suspend ReadScope<T>.(locked: Boolean) -> R

The block of code that is performed within this scope. Block will receive locked parameter which is true if the try lock succeeded.

Throws
androidx.datastore.core.IOException

when there is an unrecoverable exception in reading.

writeScope

Added in 1.1.0
suspend fun writeScope(block: suspend WriteScope<T>.() -> Unit): Unit

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.

Public properties

coordinator

Added in 1.1.0
val coordinatorInterProcessCoordinator

Provides a coordinator to guarantee data consistency across multiple threads and processes.

Extension functions

suspend fun <T : Any?> StorageConnection<T>.readData(): T
suspend fun <T : Any?> StorageConnection<T>.writeData(value: T): Unit