Public factory for creating DataStore instances.
Create an instance of SingleProcessDataStore.
@JvmOverloads fun <T> create(
produceFile: () -> File,
corruptionHandler: ReplaceFileCorruptionHandler<T>? = null,
migrations: List<DataMigration<T>> = listOf(),
scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
Create an instance of SingleProcessDataStore. The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.
T is the type DataStore acts on. The type T must be immutable. Mutating a type used in DataStore invalidates any guarantees that DataStore provides and will result in potentially serious, hard-to-catch bugs. We strongly recommend using protocol buffers: https://developers.google.com/protocol-buffers/docs/javatutorial - which provides immutability guarantees, a simple API and efficient serialization.
|produceFile: () -> File||Function which returns the file that the new DataStore will act on. The function must return the same path every time. No two instances of DataStore should act on the same file at the same time.|
|serializer: Serializer<T>||Serializer for the type T used with DataStore. The type T must be immutable.|
|corruptionHandler: ReplaceFileCorruptionHandler<T>? = null||The corruptionHandler is invoked if DataStore encounters a CorruptionException when attempting to read data. CorruptionExceptions are thrown by serializers when data can not be de-serialized.|
|migrations: List<DataMigration<T>> = listOf()||Migrations are run before any access to data can occur. Migrations must be idempotent.|
|scope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())||The scope in which IO operations and transform functions will execute.|