arrow-fx-coroutines / arrow.fx.coroutines / bracket

bracket

suspend inline fun <A, B> bracket(crossinline acquire: suspend () -> A, use: suspend (A) -> B, crossinline release: suspend (A) -> Unit): B

Describes a task with safe resource acquisition and release in the face of errors and interruption. It would be the equivalent of an async capable try/catch/finally statements in mainstream imperative languages for resource acquisition and release.

Parameters

acquire - is the action to acquire the resource.

use - is the action to consume the resource and produce a result. Once the resulting suspend program terminates, either successfully, error or disposed, the release function will run to clean up the resources.

release - is the action that’s supposed to release the allocated resource after use is done, irregardless of its exit condition.

Do you like Arrow?

Arrow Org
<