Skip to content

Avoid response buffering for ISeq response body #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kumarshantanu
Copy link

This PR makes StreamableResponseBody implementation for ISeq avoid response buffering, which is useful when the ISeq elements are delayed at source. This also allows for a smooth Server-sent Events flow.

Consider the example usage below:

(defn make-seq []
  (Thread/sleep #_10 1000)
  (str "data: " (System/currentTimeMillis) "\n\n"))

(defn handler [request]
  {:status 200
   :headers {"Content-Type" "text/event-stream"}
   :body (repeatedly make-seq)})

@weavejester
Copy link
Member

Thanks for the update. Can you change the commit message to:

Flush response body stream when writing seqs

Update the StreamableResponseBody implementation for ISeq to flush the
OutputStream after each element. This prevents unnecessary delays when
dealing with blocking seqs, for example, when being used to implement
SSEs.

This makes it clearer which system is being affected by this change. There's no need to create a new PR for this - just --amend your commit message and then force push to update the PR.

Update the StreamableResponseBody implementation for ISeq to flush the
OutputStream after each element. This prevents unnecessary delays when
dealing with blocking seqs, for example, when being used to implement
SSEs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants