|
3 | 3 | {-# LANGUAGE OverloadedStrings #-} |
4 | 4 | module Stack.Prelude |
5 | 5 | ( mapLeft |
| 6 | + , ResourceT |
6 | 7 | , runConduitRes |
| 8 | + , runResourceT |
| 9 | + , liftResourceT |
| 10 | + , NoLogging (..) |
7 | 11 | , withSystemTempDir |
8 | 12 | , fromFirst |
9 | 13 | , mapMaybeA |
@@ -107,6 +111,9 @@ import UnliftIO as X |
107 | 111 | import qualified Data.Text as T |
108 | 112 | import qualified Path.IO |
109 | 113 |
|
| 114 | +import qualified Control.Monad.Trans.Resource as Res (runResourceT, transResourceT) |
| 115 | +import Control.Monad.Trans.Resource.Internal (ResourceT (ResourceT)) |
| 116 | + |
110 | 117 | mapLeft :: (a1 -> a2) -> Either a1 b -> Either a2 b |
111 | 118 | mapLeft f (Left a1) = Left (f a1) |
112 | 119 | mapLeft _ (Right b) = Right b |
@@ -137,6 +144,22 @@ stripCR t = fromMaybe t (T.stripSuffix "\r" t) |
137 | 144 | runConduitRes :: MonadUnliftIO m => ConduitM () Void (ResourceT m) r -> m r |
138 | 145 | runConduitRes = runResourceT . runConduit |
139 | 146 |
|
| 147 | +runResourceT :: MonadUnliftIO m => ResourceT m a -> m a |
| 148 | +runResourceT r = withRunInIO $ \run -> Res.runResourceT (Res.transResourceT run r) |
| 149 | + |
| 150 | +liftResourceT :: MonadIO m => ResourceT IO a -> ResourceT m a |
| 151 | +liftResourceT (ResourceT f) = ResourceT $ liftIO . f |
| 152 | + |
| 153 | +-- | Avoid orphan messes |
| 154 | +newtype NoLogging a = NoLogging { runNoLogging :: IO a } |
| 155 | + deriving (Functor, Applicative, Monad, MonadIO) |
| 156 | +instance MonadUnliftIO NoLogging where |
| 157 | + askUnliftIO = NoLogging $ |
| 158 | + withUnliftIO $ \u -> |
| 159 | + return (UnliftIO (unliftIO u . runNoLogging)) |
| 160 | +instance MonadLogger NoLogging where |
| 161 | + monadLoggerLog _ _ _ _ = return () |
| 162 | + |
140 | 163 | -- | Path version |
141 | 164 | withSystemTempDir :: MonadUnliftIO m => String -> (Path Abs Dir -> m a) -> m a |
142 | 165 | withSystemTempDir str inner = withRunInIO $ \run -> Path.IO.withSystemTempDir str $ run . inner |
|
0 commit comments