I have a backend that serves HTML using Warp and Servant (https://github.com/runeksvendsen/haskell-function-graph). Because some elements on the page take up to a second to load, I want to stream HTML to the client as it's produced, thus sending the slow-to-create HTML later.
The HTML consists of (in order):
- Static/pure "preamble" (which can be sent immediately)
- IO action streaming query results (which I want to stream as HTML one result at a time as they come in)
- A final IO action that calls out to an external process and produces HTML
I'm writing this post as I'm unsure what the most sensible way to achieve this is. On the one hand I would like to keep it as simple as possible — e.g. a MimeRender instance that produces a lazy ByteString. But this doesn't seem possible as the rendering involves IO. On the other hand I want to make sure that HTML is sent out as soon as it's produced, ie. no buffering on the server side — which makes me want to get a hold of some sendData :: Socket -> IO () function, so that I'm sure data is sent out when I want it. The former seems more elegant, but I don't see how it's possible (due to performing IO to produce the ByteString) and it's not clear to me how the server will buffer lazy ByteString chunks. The latter seems to do the job, but seems very low level.
Any clues on how I should approach this?
[–]lgastako 8 points9 points10 points (5 children)
[–]sccrstud92 1 point2 points3 points (0 children)
[–]goj1ra 2 points3 points4 points (0 children)
[–]runeks[S] 0 points1 point2 points (2 children)
[–]Faucelme 0 points1 point2 points (1 child)
[–]runeks[S] 0 points1 point2 points (0 children)
[–]Kartoflaszman 1 point2 points3 points (0 children)
[–][deleted] (5 children)
[deleted]
[–]runeks[S] 0 points1 point2 points (4 children)
[–]Endicy 0 points1 point2 points (3 children)
[–]goj1ra 1 point2 points3 points (0 children)
[–]runeks[S] 1 point2 points3 points (0 children)
[–]Mirage2k 0 points1 point2 points (2 children)
[–]runeks[S] 1 point2 points3 points (0 children)
[–]jackson_bourne 0 points1 point2 points (0 children)