//arrow-fx-coroutines/arrow.fx.coroutines/guarantee

guarantee

common inline suspend fun <A> guarantee(fa: suspend () -> A, crossinline finalizer: suspend () -> Unit): A

Guarantees execution of a given finalizer after fa regardless of success, error or cancellation.

As best practice, it’s not a good idea to release resources via guarantee. since guarantee 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 bracket which captures acquiring, using and releasing into 3 separate steps to ensure resource safety.

See also

common

   
guaranteeCase for registering a handler that tracks the ExitCase of fa.

Parameters

common

   
fa program that you want to register handler on
finalizer handler to run after fa.

Do you like Arrow?

Arrow Org
<