Created
November 3, 2014 16:51
-
-
Save AdamClements/27948417027275d08f06 to your computer and use it in GitHub Desktop.
Writing to a webview EventSource from Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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