From c94d83f41e785c12d08c23a75b71daa540f9cd8c Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 31 Dec 2022 19:50:32 -0500 Subject: [PATCH] REF use bracket --- lib/Data/Internal/DBus.hs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Data/Internal/DBus.hs b/lib/Data/Internal/DBus.hs index 8326bd5..f895196 100644 --- a/lib/Data/Internal/DBus.hs +++ b/lib/Data/Internal/DBus.hs @@ -46,12 +46,8 @@ class SafeClient c where disconnectDBusClient = liftIO . disconnect . toClient withDBusClient :: MonadUnliftIO m => (c -> m a) -> m (Maybe a) - withDBusClient f = do - client <- getDBusClient - forM client $ \c -> do - r <- f c - liftIO $ disconnect (toClient c) - return r + withDBusClient f = + bracket getDBusClient (mapM (liftIO . disconnect . toClient)) $ mapM f withDBusClient_ :: MonadUnliftIO m => (c -> m ()) -> m () withDBusClient_ = void . withDBusClient