DisposableContainer

An implementation of DisposableRegistry that can be subclassed or used as a delegate. Allows to store and dispose of multiple Disposable instances.

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val registeredDisposables: List<Disposable>

A copy of the registered Disposables. The order does not necessarily represent the registration order.

Functions

Link copied to clipboard
open fun <T : Disposable> T.alsoDeregister(): T

Remove this Disposable from the DisposableRegistry if it is already registered.

Link copied to clipboard
open fun <T : Disposable> T.alsoRegister(): T

Register this Disposable with the DisposableRegistry.

Link copied to clipboard
open override fun deregister(disposable: Disposable): Boolean

Removes disposable from this registry.

Link copied to clipboard
open override fun deregisterAll(): Boolean

Removes all disposables from the registry without disposing them.

Link copied to clipboard
open override fun dispose()

Calls dispose on each registered Disposable. Might throw an exception if the assets were already disposed. To prevent that and clear the registry, use deregisterAll.

Link copied to clipboard
inline fun Disposable?.dispose(onError: (Exception) -> Unit)

Allows to dispose a resource implementing Disposable interface. Will silently ignore nulls. Exceptions will be caught and passed to onError function. This is basically an alternative to try-catch block usage.

Link copied to clipboard
fun Disposable?.disposeSafely()

Allows to gracefully dispose a resource implementing Disposable interface. Will silently ignore nulls and exceptions (except for JVM internal Errors, which should not be caught anyway).

Link copied to clipboard
open override fun register(disposable: Disposable): Boolean

Registers disposable with this registry.