guaranteeCase

inline suspend fun <A> guaranteeCase(fa: suspend () -> A, crossinline finalizer: suspend (ExitCase) -> Unit): A

Guarantees execution of a given finalizer after fa regardless of success, error or cancellation, allowing for differentiating between exit conditions with the ExitCase argument of the finalizer.

As best practice, it's not a good idea to release resources via guaranteeCase. since guaranteeCase doesn't properly model acquiring, using and releasing resources. It only models scheduling of a finalizer after a given suspending program, so you should prefer Resource or bracketCase which captures acquiring, using and releasing into 3 separate steps to ensure resource safety.

Parameters

fa

program that you want to register handler on

finalizer

handler to run after fa.

See also

for registering a handler that ignores the ExitCase of fa.