# 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)

*** ** * ** ***


```
public interface Closeable
```

<br />

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

|---|---|
| `https://developer.android.com/reference/androidx/datastore/core/ReadScope` | The scope used for a read transaction. |
| `https://developer.android.com/reference/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/androidx/datastore/core/WriteScope)

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

*** ** * ** ***

Datastore common version of java.io.Closeable

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/datastore/core/Closeable#close()()` Closes the specified resource. |

| ### Extension functions |
|---|---|
| `default final @https://developer.android.com/reference/androidx/annotation/NonNull R` | `<T extends https://developer.android.com/reference/androidx/datastore/core/Closeable, R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/datastore/core/CloseableKt.https://developer.android.com/reference/androidx/datastore/core/Closeable#(androidx.datastore.core.Closeable).use(kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull T receiver, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull T, @https://developer.android.com/reference/androidx/annotation/NonNull R> block )` Ensures a Closeable object has its close() method called at the end of the supplied block. |

## Public methods

### close

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

```
abstract void close()
```

Closes the specified resource.

## Extension functions

### CloseableKt.use

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)

```
default final @NonNull R <T extends Closeable, R extends Object> CloseableKt.use(
    @NonNull T receiver,
    @NonNull Function1<@NonNull T, @NonNull R> block
)
```

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