Fork me on GitHub
#aleph
<
2022-05-20
>
lilactown02:05:56

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

lilactown02:05:03

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}))

lilactown02:05:16

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

lilactown02:05:48

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

Matthew Davidson (kingmob)11:05:35

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 😄

lilactown14:05:31

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

lilactown22:05:22

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

lilactown22:05:34

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

lilactown22:05:17

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

Matthew Davidson (kingmob)04:05:54

Ahh, good ol’ SafarIE