aleph

lilactown 2022-05-20T02:04:56.617859Z

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

lilactown 2022-05-20T02:06:03.202489Z

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

lilactown 2022-05-20T02:08:16.280869Z

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

lilactown 2022-05-20T02:08:48.165059Z

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

Matthew Davidson 2022-05-20T11:32:35.780989Z

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 😄

lilactown 2022-05-20T14:34:31.371019Z

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

lilactown 2022-05-20T22:12:22.644449Z

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

lilactown 2022-05-20T22:12:34.393159Z

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

lilactown 2022-05-20T22:15:17.267939Z

> 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 2022-05-21T04:00:54.115719Z

Ahh, good ol’ SafarIE