diff options
author | Paul Oliver <contact@pauloliver.dev> | 2025-08-20 19:10:16 +0000 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2025-08-23 22:59:12 +0000 |
commit | 82b02509150b615360118ca381ad8c9fd39d2f29 (patch) | |
tree | 97118f30a334a7b1fc9b6b7f6a8bbcbc87ae5aeb /hsm-pwm | |
parent | dea39a25938662e6af932bc9a957073d8364dde1 (diff) |
Falls back to `bracket` unless `releaseEff` is needed
Diffstat (limited to 'hsm-pwm')
-rw-r--r-- | hsm-pwm/Hsm/PWM.hs | 12 | ||||
-rw-r--r-- | hsm-pwm/hsm-pwm.cabal | 1 |
2 files changed, 4 insertions, 9 deletions
diff --git a/hsm-pwm/Hsm/PWM.hs b/hsm-pwm/Hsm/PWM.hs index 400e704..9a4fe5c 100644 --- a/hsm-pwm/Hsm/PWM.hs +++ b/hsm-pwm/Hsm/PWM.hs @@ -20,7 +20,7 @@ module Hsm.PWM where import Control.Concurrent (threadDelay) -import Control.Monad (forM_, void) +import Control.Monad (forM_) import Control.Monad.Loops (untilM_) import Effectful (Dispatch (Static), DispatchOf, Eff, IOE, liftIO, (:>)) import Effectful.Dispatch.Static @@ -29,7 +29,7 @@ import Effectful.Dispatch.Static , evalStaticRep , unsafeEff_ ) -import Effectful.Resource (Resource, allocateEff_) +import Effectful.Exception (bracket_) import Hsm.Core.Serial (makeSerial) import Hsm.Log (Log, Severity (Info, Trace), logMsg) import System.FilePath ((</>)) @@ -100,12 +100,8 @@ setCycleDuration channel cycleDuration = do setDutyCycle channel $ cycleDuration `div` 2 setEnable channel True -runPWM - :: (IOE :> es, Log "pwm" :> es, Resource :> es) => Eff (PWM : es) a -> Eff es a -runPWM action = - evalStaticRep (PWM ()) $ do - void $ allocateEff_ pwmAlloc pwmDealloc - action +runPWM :: (IOE :> es, Log "pwm" :> es) => Eff (PWM : es) a -> Eff es a +runPWM = evalStaticRep (PWM ()) . bracket_ pwmAlloc pwmDealloc where exportPath = chipPath </> "export" unexportPath = chipPath </> "unexport" diff --git a/hsm-pwm/hsm-pwm.cabal b/hsm-pwm/hsm-pwm.cabal index 2f3134a..808c7cb 100644 --- a/hsm-pwm/hsm-pwm.cabal +++ b/hsm-pwm/hsm-pwm.cabal @@ -12,7 +12,6 @@ library , hsm-core , hsm-log , monad-loops - , resourcet-effectful , unix default-language: GHC2024 |