REF use bracket

This commit is contained in:
Nathan Dwarshuis 2022-12-31 19:50:32 -05:00
parent b52b22c48d
commit c94d83f41e
1 changed files with 2 additions and 6 deletions

View File

@ -46,12 +46,8 @@ class SafeClient c where
disconnectDBusClient = liftIO . disconnect . toClient disconnectDBusClient = liftIO . disconnect . toClient
withDBusClient :: MonadUnliftIO m => (c -> m a) -> m (Maybe a) withDBusClient :: MonadUnliftIO m => (c -> m a) -> m (Maybe a)
withDBusClient f = do withDBusClient f =
client <- getDBusClient bracket getDBusClient (mapM (liftIO . disconnect . toClient)) $ mapM f
forM client $ \c -> do
r <- f c
liftIO $ disconnect (toClient c)
return r
withDBusClient_ :: MonadUnliftIO m => (c -> m ()) -> m () withDBusClient_ :: MonadUnliftIO m => (c -> m ()) -> m ()
withDBusClient_ = void . withDBusClient withDBusClient_ = void . withDBusClient