Bracket
public protocol Bracket : MonadError
Bracket models a generalized abstracted pattern of safe resource acquisition and release in the face of errors or interruptions.
-
A way to safely acquire a resource and release in the face of errors and cancellations. It uses
ExitCase
to distinguish between different exit cases when releasing the acquired resource.Declaration
Parameters
fa
Computation to describe the acquisition of the resource.
release
Function to release the acquired resource.
use
Function to use the acquired resource.
Return Value
Computation describing the result of using the resource.
-
bracket(acquire:release:use:)
Extension methodA way to safely acquire a resource and release in the face of errors and cancellations. It uses
ExitCase
to distinguish between different exit cases when releasing the acquired resource.Declaration
Parameters
fa
Computation to describe the acquisition of the resource.
release
Function to release the acquired resource, ignoring the outcome of the release of the resource.
use
Function to use the acquired resource.
Return Value
Computation describing the result of using the resource.
-
uncancelable(_:)
Extension method -
guarantee(_:finalizer:)
Extension methodExecutes the given finalizer when the source is finished, either in success, error or cancelation.
Declaration
Parameters
fa
Computation describing the acquisition of the resource.
finalizer
Finalizer function to be invoked when the resource is released.
Return Value
A computation describing the resouce that will invoke the finalizer when it is released.
-
guaranteeCase(_:finalizer:)
Extension methodExecutes the given finalizer when the source is finished, either in success, error or cancelation, alowing to differentiate between exit conditions.
Declaration
Parameters
fa
Computation describing the acquisition of the resource.
finalizer
Finalizer function to be invoked when the resource is released, distinguishing the exit case.
Return Value
A computation describing the resource that will invoke the finalizer when it is released.