A way to safely acquire a resource and release in the face of errors and cancellation. It uses ExitCase to distinguish between different exit cases when releasing the acquired resource.
Bracket exists out of a three stages:
Resource acquisition is NON CANCELABLE.
If resource acquisition fails, meaning no resource was actually successfully acquired then we short-circuit the effect.
Reason being, we cannot release what we did not
acquire first. Same reason we cannot call use.
If it is successful we pass the result to stage 2 use.
Resource consumption is like any other IO effect. The key difference here is that it’s wired in such a way that
release will always be called either on ExitCase.Canceled, ExitCase.Error or ExitCase.Completed.
If it failed than the resulting IO from bracketCase will be
IO.raiseError(e), otherwise the result of use.
use - is the action to consume the resource and produce an IO with the result.
Once the resulting IO terminates, either successfully, error or disposed,
the release function will run to clean up the resources.
Do you like Arrow?✖