-
-
Save dotemacs/28279b24354e7d3cc3fb04ace0f90558 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