ResourceManager
Resource Manager
Simple implementation of LifecycleBoundResources, which propagates close calls to resources registered to it. Implementations are intended to use delegation:
class MyResourceHolder(
private val manager: LifecycleBoundResources = ResourceManager()
): LifecycleBoundResources by manager, AutoCloseable by manager {
// ...
private fun somethingThatSpawnsAResource() {
val resource = // ...
register(resource)
}
}
// later ...
val instance = MyResourceHolder()
instance.use {
// the inner resource will be closed automatically
}
Content copied to clipboard
Functions
Link copied to clipboard
Register an AutoCloseable resource to this lifecycle.
Unregister an AutoCloseable resource from this lifecycle.