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