on master help sign in
wai-eventsource: Do not a blaze-builder flush on eventToBuilder.

Adding a blaze-builder flush there has the disadvantage of creating an HTTP chunk for each event on the response. OTOH, it has no advantage: a wai Flush is added after each wai Chunk by all functions from the EventSource module, so the blaze-builder flush is redundant. Note that this commit does not change the behaviour of the EventSource module at all. It only changes the behaviour of any 3rd party code using EventStream (which I assume is only mine's for now :]).

commit9e14315fa85c64d8882ca48655fe0a691a6bfd7b authorFelipe Lessa <felipe.lessa@gmail.com> dateSun 29 Jul 2012, 12:56 (14 years ago) parent22aefe4
1 file changed+3−10
wai-eventsource/src/Network/Wai/EventSource/EventStream.hs+3−10
wai-eventsource/src/Network/Wai/EventSource/EventStream.hs+3−10
@@ -58,22 +58,15 @@ field :: Builder -> Builder -> Builder
5858field l b = l `mappend` b `mappend` nl
5959
6060
61−{-|
62− Appends a buffer flush to the end of a Builder.
63−-}
64−flushAfter :: Builder -> Builder
65−flushAfter b = b `mappend` flush
66−
67−
6861{-|
6962 Converts a 'ServerEvent' to its wire representation as specified by the
7063 @text/event-stream@ content type.
7164-}
7265eventToBuilder :: ServerEvent -> Maybe Builder
73−eventToBuilder (CommentEvent txt) = Just $ flushAfter $ field commentField txt
74−eventToBuilder (RetryEvent n) = Just $ flushAfter $ field retryField (fromShow n)
66+eventToBuilder (CommentEvent txt) = Just $ field commentField txt
67+eventToBuilder (RetryEvent n) = Just $ field retryField (fromShow n)
7568eventToBuilder (CloseEvent) = Nothing
76−eventToBuilder (ServerEvent n i d)= Just $ flushAfter $
69+eventToBuilder (ServerEvent n i d)= Just $
7770 (name n $ evid i $ mconcat (map (field dataField) d)) `mappend` nl
7871 where
7972 name Nothing = id