Created
September 1, 2017 12:32
-
-
Save cgrand/eea3bf5afdfc5554cbd14fb85dee90f9 to your computer and use it in GitHub Desktop.
pseudo code for back pressure bridging
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
(a/go-loop [async-tcp-connections-to-chans ; "foreign" -> ch | |
buffered ; ch -> data | |
pressurized] ; ch -> foreign | |
(let [cnx (select (keys async-tcp-connections-to-chans)) | |
ch (async-tcp-connections-to-chans cnx) | |
data (read-data cnx) | |
async-tcp-connections-to-chans (dissoc async-tcp-connections-to-chans cnx) | |
buffered (assoc buffered ch data) | |
pressurized (assoc pressurized ch cnx)] | |
(let [[_ c] (a/alts! (vec buffered) | |
:default :bp)] | |
(if (= :default c) | |
(recur async-tcp-connections-to-chans buffered pressurized) | |
(let [cnx (pressurized c)] | |
(recur (assoc async-tcp-connections-to-chans cnx c) | |
(dissoc buffered c) | |
(dissoc pressurized c))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment