Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pseudo code for back pressure bridging
(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