Browse files

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 :]).
  • Loading branch information...
1 parent 22aefe4 commit 9e14315fa85c64d8882ca48655fe0a691a6bfd7b @meteficha meteficha committed Jul 29, 2012
Showing with 3 additions and 10 deletions.
  1. +3 −10 wai-eventsource/src/Network/Wai/EventSource/EventStream.hs
13 wai-eventsource/src/Network/Wai/EventSource/EventStream.hs
@@ -59,21 +59,14 @@ field l b = l `mappend` b `mappend` nl
- Appends a buffer flush to the end of a Builder.
-flushAfter :: Builder -> Builder
-flushAfter b = b `mappend` flush
Converts a 'ServerEvent' to its wire representation as specified by the
@text/event-stream@ content type.
eventToBuilder :: ServerEvent -> Maybe Builder
-eventToBuilder (CommentEvent txt) = Just $ flushAfter $ field commentField txt
-eventToBuilder (RetryEvent n) = Just $ flushAfter $ field retryField (fromShow n)
+eventToBuilder (CommentEvent txt) = Just $ field commentField txt
+eventToBuilder (RetryEvent n) = Just $ field retryField (fromShow n)
eventToBuilder (CloseEvent) = Nothing
-eventToBuilder (ServerEvent n i d)= Just $ flushAfter $
+eventToBuilder (ServerEvent n i d)= Just $
(name n $ evid i $ mconcat (map (field dataField) d)) `mappend` nl
name Nothing = id

0 comments on commit 9e14315

Please sign in to comment.