summaryrefslogtreecommitdiff
path: root/Assistant/Monad.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-16 00:12:28 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-16 00:19:56 -0400
commit2274b305d41b1feb840fe9dd5dabd3b2f705a5ee (patch)
tree31e74939426ddce12a309d2418b9995adb4f807e /Assistant/Monad.hs
parent242c2e577b8545c2e9ed117ce7196afcf361ed57 (diff)
make liftAnnex and liftAssistant polymorphic, like liftIO
Diffstat (limited to 'Assistant/Monad.hs')
-rw-r--r--Assistant/Monad.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/Assistant/Monad.hs b/Assistant/Monad.hs
index 140b9f582..e046c9666 100644
--- a/Assistant/Monad.hs
+++ b/Assistant/Monad.hs
@@ -13,6 +13,7 @@ module Assistant.Monad (
newAssistantData,
runAssistant,
getAssistant,
+ LiftAnnex,
liftAnnex,
(<~>),
(<<~),
@@ -90,13 +91,18 @@ runAssistant d a = runReaderT (mkAssistant a) d
getAssistant :: (AssistantData -> a) -> Assistant a
getAssistant = reader
+{- Using a type class for lifting into the annex monad allows
+ - easily lifting to it from multiple different monads. -}
+class LiftAnnex m where
+ liftAnnex :: Annex a -> m a
+
{- Runs an action in the git-annex monad. Note that the same monad state
- is shared amoung all assistant threads, so only one of these can run at
- a time. Therefore, long-duration actions should be avoided. -}
-liftAnnex :: Annex a -> Assistant a
-liftAnnex a = do
- st <- reader threadState
- liftIO $ runThreadState st a
+instance LiftAnnex Assistant where
+ liftAnnex a = do
+ st <- reader threadState
+ liftIO $ runThreadState st a
{- Runs an IO action, passing it an IO action that runs an Assistant action. -}
(<~>) :: (IO a -> IO b) -> Assistant a -> Assistant b