on master help sign in
Change definition of StreamGenerator
0ba09c9Jan van Brügge
servant-server/src/Servant/Server/Internal.hs+10−10
@@ -284,10 +284,10 @@ instance OVERLAPPING_
284
284
285instance OVERLAPPABLE_
285instance OVERLAPPABLE_
286 ( MimeRender ctype a, ReflectMethod method,
286 ( MimeRender ctype a, ReflectMethod method,
287− FramingRender framing ctype, ToStreamGenerator f a
287+ FramingRender framing ctype, ToStreamGenerator b a
288− ) => HasServer (Stream method framing ctype (f a)) context where
288+ ) => HasServer (Stream method framing ctype b) context where
289
289
290− type ServerT (Stream method framing ctype (f a)) m = m (f a)
290+ type ServerT (Stream method framing ctype b) m = m b
291 hoistServerWithContext _ _ nt s = nt s
291 hoistServerWithContext _ _ nt s = nt s
292
292
293 route Proxy _ = streamRouter ([],) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
293 route Proxy _ = streamRouter ([],) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
@@ -295,23 +295,23 @@ instance OVERLAPPABLE_
295
295
296instance OVERLAPPING_
296instance OVERLAPPING_
297 ( MimeRender ctype a, ReflectMethod method,
297 ( MimeRender ctype a, ReflectMethod method,
298− FramingRender framing ctype, ToStreamGenerator f a,
298+ FramingRender framing ctype, ToStreamGenerator b a,
299− GetHeaders (Headers h (f a))
299+ GetHeaders (Headers h b)
300− ) => HasServer (Stream method framing ctype (Headers h (f a))) context where
300+ ) => HasServer (Stream method framing ctype (Headers h b)) context where
301
301
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)
303 hoistServerWithContext _ _ nt s = nt s
303 hoistServerWithContext _ _ nt s = nt s
304
304
305 route Proxy _ = streamRouter (\x -> (getHeaders x, getResponse x)) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
305 route Proxy _ = streamRouter (\x -> (getHeaders x, getResponse x)) method (Proxy :: Proxy framing) (Proxy :: Proxy ctype)
306 where method = reflectMethod (Proxy :: Proxy method)
306 where method = reflectMethod (Proxy :: Proxy method)
307
307
308
308
309−streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator f a) =>
309+streamRouter :: (MimeRender ctype a, FramingRender framing ctype, ToStreamGenerator b a) =>
310− (b -> ([(HeaderName, B.ByteString)], f a))
310+ (c -> ([(HeaderName, B.ByteString)], b))
311 -> Method
311 -> Method
312 -> Proxy framing
312 -> Proxy framing
313 -> Proxy ctype
313 -> Proxy ctype
314− -> Delayed env (Handler b)
314+ -> Delayed env (Handler c)
315 -> Router env
315 -> Router env
316streamRouter splitHeaders method framingproxy ctypeproxy action = leafRouter $ \env request respond ->
316streamRouter splitHeaders method framingproxy ctypeproxy action = leafRouter $ \env request respond ->
317 let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
317 let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
servant/src/Servant/API/Stream.hs+5−4
@@ -2,6 +2,7 @@
2{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE KindSignatures #-}
6{-# LANGUAGE KindSignatures #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE OverloadedStrings #-}
8{-# LANGUAGE OverloadedStrings #-}
@@ -38,13 +39,13 @@ type StreamGet = Stream 'GET
38type StreamPost = Stream 'POST
39type StreamPost = Stream 'POST
39
40
40-- | 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-- | 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 ()}
42
43
43-- | 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-- | 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+class ToStreamGenerator a b | a -> b where
45− toStreamGenerator :: f a -> StreamGenerator a
46+ toStreamGenerator :: a -> StreamGenerator b
46
47
47−instance ToStreamGenerator StreamGenerator a
48+instance ToStreamGenerator (StreamGenerator a) a
48 where toStreamGenerator x = x
49 where toStreamGenerator x = x
49
50
50-- | 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.
51-- | 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.