Created
February 12, 2020 21:15
-
-
Save erikkaplun/af2ec98efbe5cca8b5295966f91db3bc to your computer and use it in GitHub Desktop.
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
(defn convert-stream [f-sink f-src s] | |
(let [sink (s/stream) | |
src (s/map f-src s)] | |
(s/connect-via sink #(s/put! s (f-sink %)) s) | |
(s/splice sink src))) | |
(defn make-duplex-stream [] | |
(let [sink (s/stream) | |
src (s/stream) | |
duplex (s/splice sink src)] | |
[sink src duplex])) | |
(defn test-convert-stream [] | |
(let [[conn-sink conn-src fake-conn] (make-duplex-stream) | |
msgs (convert-stream u/->json u/json-> fake-conn)] | |
;; serialized message from mock client | |
(s/put! conn-sink "{\"message\": \"hello\"}") | |
;; should be decoded from JSON | |
(prn 'got @(s/take! msgs)) | |
;; send unserialized message to mock client | |
(s/put! msgs {"message" "bye"}) | |
;; shoild be serialized JSON | |
(prn 'to-be-sent @(s/take! conn-src)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment