diff --git a/bluefin-internal/src/Bluefin/Internal.hs b/bluefin-internal/src/Bluefin/Internal.hs index 64bb79b..89dd252 100644 --- a/bluefin-internal/src/Bluefin/Internal.hs +++ b/bluefin-internal/src/Bluefin/Internal.hs @@ -390,6 +390,19 @@ catch :: Eff es a catch f h = handle h f +-- | @bracket acquire release body@: @acquire@ a resource, perform the +-- @body@ with it, and @release@ the resource even if @body@ threw an +-- exception. This is essentially the same as +-- @Control.Exception.'Control.Exception.bracket'@, whose +-- documentation you can inspect for further details. +bracket :: + Eff es a -> + (a -> Eff es ()) -> + (a -> Eff es b) -> + Eff es b +bracket before after body = UnsafeMkEff $ Control.Exception.bracket + (unsafeUnEff before) (unsafeUnEff . after) (unsafeUnEff . body) + -- | -- @ -- >>> runPureEff $ runState 10 $ \\st -> do diff --git a/bluefin/src/Bluefin/Eff.hs b/bluefin/src/Bluefin/Eff.hs index 891e9b1..2e8ef79 100644 --- a/bluefin/src/Bluefin/Eff.hs +++ b/bluefin/src/Bluefin/Eff.hs @@ -4,6 +4,8 @@ module Bluefin.Eff -- * Run an 'Eff' runPureEff, runEff, + -- * Resource management + bracket, -- * Type classes -- | See "Bluefin.Eff.IO" for the most direct way of doing I/O in