1
- {-# LANGUAGE DeriveDataTypeable #-}
2
- {-# LANGUAGE DeriveGeneric #-}
3
- {-# LANGUAGE CPP #-}
4
- {-# LANGUAGE OverloadedStrings #-}
5
- {-# LANGUAGE ScopedTypeVariables #-}
6
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
1
+ {-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE DeriveDataTypeable #-}
3
+ {-# LANGUAGE DeriveGeneric #-}
4
+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5
+ {-# LANGUAGE MultiParamTypeClasses #-}
6
+ {-# LANGUAGE TypeFamilies #-}
7
+ {-# LANGUAGE OverloadedStrings #-}
8
+ {-# LANGUAGE ScopedTypeVariables #-}
7
9
8
10
module Servant.Common.Req where
9
11
@@ -24,8 +26,10 @@ import Control.Monad.Trans.Except
24
26
25
27
26
28
import GHC.Generics
29
+ import Control.Monad.Base (MonadBase (.. ))
27
30
import Control.Monad.IO.Class ()
28
31
import Control.Monad.Reader
32
+ import Control.Monad.Trans.Control (MonadBaseControl (.. ))
29
33
import Data.ByteString.Lazy hiding (pack , filter , map , null , elem , any )
30
34
import Data.String
31
35
import Data.String.Conversions
@@ -180,6 +184,18 @@ newtype ClientM a = ClientM { runClientM' :: ReaderT ClientEnv (ExceptT ServantE
180
184
, MonadThrow , MonadCatch
181
185
)
182
186
187
+ instance MonadBase IO ClientM where
188
+ liftBase = ClientM . liftBase
189
+
190
+ instance MonadBaseControl IO ClientM where
191
+ type StM ClientM a = Either ServantError a
192
+
193
+ -- liftBaseWith :: (RunInBase ClientM IO -> IO a) -> ClientM a
194
+ liftBaseWith f = ClientM (liftBaseWith (\ g -> f (g . runClientM')))
195
+
196
+ -- restoreM :: StM ClientM a -> ClientM a
197
+ restoreM st = ClientM (restoreM st)
198
+
183
199
runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a )
184
200
runClientM cm env = runExceptT $ (flip runReaderT env) $ runClientM' cm
185
201
0 commit comments