on master help sign in
Change definition of StreamGenerator
commit0ba09c999b07898166afe121cf380d99454f79ee authorJan van Brügge <supermanitu@gmail.com> dateWed 16 May 2018, 12:50 (8 years ago) parent3e8c217
2 files changed+15−14
servant-server/src/Servant/Server/Internal.hs+10−10 servant/src/Servant/API/Stream.hs+5−4
servant-server/src/Servant/Server/Internal.hs+10−10
@@ -284,10 +284,10 @@ instance OVERLAPPING_
284284
285285instance OVERLAPPABLE_
286286 ( MimeRender ctype a, ReflectMethod method,
287− FramingRender framing ctype, ToStreamGenerator f a
288− ) => HasServer (Stream method framing ctype (f a)) context where
287+ FramingRender framing ctype, ToStreamGenerator b a
288+ ) => HasServer (Stream method framing ctype b) context where
289289
290− type ServerT (Stream method framing ctype (f a)) m = m (f a)
290+ type ServerT (Stream method framing ctype b) m = m b
291291 hoistServerWithContext _ _ nt s = nt s
292292
293293 route Proxy _ = streamRouter ([],) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
@@ -295,23 +295,23 @@ instance OVERLAPPABLE_
295295
296296instance OVERLAPPING_
297297 ( MimeRender ctype a, ReflectMethod method,
298− FramingRender framing ctype, ToStreamGenerator f a,
299− GetHeaders (Headers h (f a))
300− ) => HasServer (Stream method framing ctype (Headers h (f a))) context where
298+ FramingRender framing ctype, ToStreamGenerator b a,
299+ GetHeaders (Headers h b)
300+ ) => HasServer (Stream method framing ctype (Headers h b)) context where
301301
302− type ServerT (Stream method framing ctype (Headers h (f a))) m = m (Headers h (f a))
302+ type ServerT (Stream method framing ctype (Headers h b)) m = m (Headers h b)
303303 hoistServerWithContext _ _ nt s = nt s
304304
305305 route Proxy _ = streamRouter (\x -> (getHeaders x, getResponse x)) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
306306 where method = reflectMethod (Proxy :: Proxy method)
307307
308308
309−streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator f a) =>
310− (b -> ([(HeaderName, B.ByteString)], f a))
309+streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator b a) =>
310+ (c -> ([(HeaderName, B.ByteString)], b))
311311 -> Method
312312 -> Proxy framing
313313 -> Proxy ctype
314− -> Delayed env (Handler b)
314+ -> Delayed env (Handler c)
315315 -> Router env
316316streamRouter splitHeaders method framingproxy ctypeproxy action = leafRouter $ \env request respond ->
317317 let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
servant/src/Servant/API/Stream.hs+5−4
@@ -2,6 +2,7 @@
22{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE FunctionalDependencies #-}
56{-# LANGUAGE KindSignatures #-}
67{-# LANGUAGE MultiParamTypeClasses #-}
78{-# LANGUAGE OverloadedStrings #-}
@@ -38,13 +39,13 @@ type StreamGet = Stream 'GET
3839type StreamPost = Stream 'POST
3940
4041-- | Stream endpoints may be implemented as producing a @StreamGenerator@ -- a function that itself takes two emit functions -- the first to be used on the first value the stream emits, and the second to be used on all subsequent values (to allow interspersed framing strategies such as comma separation).
41−newtype StreamGenerator a = StreamGenerator {getStreamGenerator :: (a -> IO ()) -> (a -> IO ()) -> IO ()}
42+newtype StreamGenerator a = StreamGenerator {getStreamGenerator :: (a -> IO ()) -> (a -> IO ()) -> IO ()}
4243
4344-- | ToStreamGenerator is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly as endpoints.
44−class ToStreamGenerator f a where
45− toStreamGenerator :: f a -> StreamGenerator a
45+class ToStreamGenerator a b | a -> b where
46+ toStreamGenerator :: a -> StreamGenerator b
4647
47−instance ToStreamGenerator StreamGenerator a
48+instance ToStreamGenerator (StreamGenerator a) a
4849 where toStreamGenerator x = x
4950
5051-- | Clients reading from streaming endpoints can be implemented as producing a @ResultStream@ that captures the setup, takedown, and incremental logic for a read, being an IO continuation that takes a producer of Just either values or errors that terminates with a Nothing.