Skip to content

Commit b548f8d

Browse files
committed
Add MonadBaseControl IO ClientM instance
1 parent 875f592 commit b548f8d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

servant-client/servant-client.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ library
4747
, http-client-tls >= 0.2.2 && < 0.4
4848
, http-media >= 0.6.2 && < 0.7
4949
, http-types >= 0.8.6 && < 0.10
50+
, monad-control >= 1.0.0.4 && < 1.1
5051
, network-uri >= 2.6 && < 2.7
5152
, safe >= 0.3.9 && < 0.4
5253
, servant == 0.9.*
5354
, string-conversions >= 0.3 && < 0.5
5455
, text >= 1.2 && < 1.3
5556
, transformers >= 0.3 && < 0.6
57+
, transformers-base >= 0.4.4 && < 0.5
5658
, transformers-compat >= 0.4 && < 0.6
5759
, mtl
5860
hs-source-dirs: src

servant-client/src/Servant/Common/Req.hs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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 #-}
79

810
module Servant.Common.Req where
911

@@ -24,8 +26,10 @@ import Control.Monad.Trans.Except
2426

2527

2628
import GHC.Generics
29+
import Control.Monad.Base (MonadBase (..))
2730
import Control.Monad.IO.Class ()
2831
import Control.Monad.Reader
32+
import Control.Monad.Trans.Control (MonadBaseControl (..))
2933
import Data.ByteString.Lazy hiding (pack, filter, map, null, elem, any)
3034
import Data.String
3135
import Data.String.Conversions
@@ -180,6 +184,18 @@ newtype ClientM a = ClientM { runClientM' :: ReaderT ClientEnv (ExceptT ServantE
180184
, MonadThrow, MonadCatch
181185
)
182186

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+
183199
runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a)
184200
runClientM cm env = runExceptT $ (flip runReaderT env) $ runClientM' cm
185201

0 commit comments

Comments
 (0)