aleph 2022-05-20

I'm returning a stream as the body of a handler. I'm noticing that streaming the results seems to hang until a certain amount of content is put into the stream

e.g.

(defn handler [req]
  (let [stream (s/stream)]
    (doseq [i (range 0 100)]
      (s/put! stream i))
    (d/future
     (Thread/sleep 4000)
     (s/close! stream))
    {:status 200
     :headers {"content-type" "text/plain"}
     :body stream}))

this will wait until the stream is closed (4 seconds later) to send the content to the client

I'd like to be able to flush it manually, ideally. is there a way to do that?

Hmm, well there are some flush fns in aleph.netty, but they’re not really designed to be used directly. I’ll take a closer look at the delay in the next few days, it kind of defeats the point of a streaming server if it can’t, ya know, stream 😄

yeah. if I shove a bunch more data down the pipe (e.g. 1000 numbers) then it will send it to the client quickly, and keep the connection open until the stream closes, which is what I want

this might actually be a safari issue. I don't see the same behavior on chrome

so it might be safari that is waiting to render the results

> Ok in order for Safari to render the html at least 1024 bytes have to be written before it starts to render as received. 🆒

Ahh, good ol’ SafarIE