StorageConnection



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.

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

Cmn

Public properties

InterProcessCoordinator

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

Cmn

Extension functions

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

Inherited functions

From androidx.datastore.core.Closeable
Unit

Closes the specified resource.

Cmn

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

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

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