Skip to content

Instantly share code, notes, and snippets.

@AdamClements
Created November 3, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamClements/27948417027275d08f06 to your computer and use it in GitHub Desktop.
Save AdamClements/27948417027275d08f06 to your computer and use it in GitHub Desktop.
Writing to a webview EventSource from Clojure
(def data-chan (async/chan))
(defn webview-writer [chan]
(let [istream (PipedInputStream.)
ostream (PipedOutputStream. istream)]
(async/thread
(loop []
(when-some [s (async/<!! chan)]
(let [event (str "event: test\ndata: "s"\n\n")]
(.write ostream (.getBytes event "UTF-8"))
(.flush ostream))
(recur))))
istream))
... pass istream to a webview WebRequestResponse which internally uses EventSource in js to read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment