@@ -13,11 +13,11 @@ module Servant.Server.Internal.RoutingApplication where
13
13
import Control.Monad (ap , liftM )
14
14
import Control.Monad.Base (MonadBase (.. ))
15
15
import Control.Monad.Catch (MonadThrow (.. ))
16
- import Control.Monad.Reader (MonadReader (.. ), ReaderT , runReaderT )
16
+ import Control.Monad.Reader (MonadReader (.. ), ReaderT ( .. ) , runReaderT )
17
17
import Control.Monad.Trans (MonadIO (.. ), MonadTrans (.. ))
18
18
import Control.Monad.Trans.Control (ComposeSt , MonadBaseControl (.. ), MonadTransControl (.. ),
19
19
defaultLiftBaseWith , defaultRestoreM )
20
- import Control.Monad.Trans.Resource (MonadResource (.. ), ResourceT , runResourceT , transResourceT )
20
+ import Control.Monad.Trans.Resource (MonadResource (.. ), ResourceT , runResourceT , transResourceT , withInternalState , runInternalState )
21
21
import Network.Wai (Application , Request , Response , ResponseReceived )
22
22
import Prelude ()
23
23
import Prelude.Compat
@@ -84,7 +84,6 @@ instance MonadTransControl RouteResultT where
84
84
instance MonadThrow m => MonadThrow (RouteResultT m ) where
85
85
throwM = lift . throwM
86
86
87
-
88
87
toApplication :: RoutingApplication -> Application
89
88
toApplication ra request respond = ra request routingRespond
90
89
where
@@ -194,18 +193,27 @@ newtype DelayedIO a = DelayedIO { runDelayedIO' :: ReaderT Request (ResourceT (R
194
193
deriving
195
194
( Functor , Applicative , Monad
196
195
, MonadIO , MonadReader Request
197
- , MonadBase IO
198
196
, MonadThrow
199
197
, MonadResource
200
198
)
201
199
200
+ instance MonadBase IO DelayedIO where
201
+ liftBase = liftIO
202
+
202
203
liftRouteResult :: RouteResult a -> DelayedIO a
203
204
liftRouteResult x = DelayedIO $ lift . lift $ RouteResultT . return $ x
204
205
205
206
instance MonadBaseControl IO DelayedIO where
206
- type StM DelayedIO a = StM (ReaderT Request (ResourceT (RouteResultT IO ))) a
207
- liftBaseWith f = DelayedIO $ liftBaseWith $ \ g -> f (g . runDelayedIO')
208
- restoreM = DelayedIO . restoreM
207
+ -- type StM DelayedIO a = StM (ReaderT Request (ResourceT (RouteResultT IO))) a
208
+ -- liftBaseWith f = DelayedIO $ liftBaseWith $ \g -> f (g . runDelayedIO')
209
+ -- restoreM = DelayedIO . restoreM
210
+
211
+ type StM DelayedIO a = RouteResult a
212
+ liftBaseWith f = DelayedIO $ ReaderT $ \ req -> withInternalState $ \ s ->
213
+ liftBaseWith $ \ runInBase -> f $ \ x ->
214
+ runInBase (runInternalState (runReaderT (runDelayedIO' x) req) s)
215
+ restoreM = DelayedIO . lift . withInternalState . const . restoreM
216
+
209
217
210
218
runDelayedIO :: DelayedIO a -> Request -> ResourceT IO (RouteResult a )
211
219
runDelayedIO m req = transResourceT runRouteResultT $ runReaderT (runDelayedIO' m) req
0 commit comments