Fork me on GitHub

@lxsameer or if you use put! make sure you also use a callback that limits how soon you call put! again. That's really the key here, put! requires manual implementation of backpressure


Sometimes that's easy (like when dealing with a async message queue), sometimes it's harder


A go-loop that pipes from in to out is really nothing more than this:

(defn pipe [in out]
  (take! in
            (fn [val]
              (when val
                (put! out 
                   (fn [put?}
                     (when put?
                       (pipe in out)))))))) 
That handles back pressure just fine, but as you can see it's a bit more ugly than:
(defn pipe [in out
  (go-loop []
    (when-some [val (<! in)]
      (when (>! out val)