# Closeable

Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/Closeable.kt+class:androidx.datastore.core.Closeable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface Closeable
  ```
Known direct subclasses [ReadScope](https://developer.android.com/reference/kotlin/androidx/datastore/core/ReadScope), [StorageConnection](https://developer.android.com/reference/kotlin/androidx/datastore/core/StorageConnection)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/ReadScope` | The scope used for a read transaction. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/StorageConnection` | StorageConnection provides a way to read and write a particular type of data. |

Known indirect subclasses [WriteScope](https://developer.android.com/reference/kotlin/androidx/datastore/core/WriteScope)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/WriteScope` | The scope used for a write transaction. |

*** ** * ** ***

Datastore common version of java.io.Closeable

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/Closeable#close()()` Closes the specified resource. | Cmn |

| ### Extension functions |
|---|---|---|
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/datastore/core/Closeable, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.https://developer.android.com/reference/kotlin/androidx/datastore/core/Closeable#(androidx.datastore.core.Closeable).use(kotlin.Function1)(block: (T) -> R)` Ensures a Closeable object has its close() method called at the end of the supplied block. | Cmn |

## Public functions

### close

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

```
fun close(): Unit
```

Closes the specified resource.

## Extension functions

### T.use

Cmn Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/Closeable.kt+function:use)

```
inline fun <T : Closeable, R : Any?> T.use(block: (T) -> R): R
```

Ensures a Closeable object has its close() method called at the end of the supplied block.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` | any exceptions thrown in the block will propagate through this method. |