title: Clojure async/go how to park blocking code
body: <p>I use some Java library that makes non-async get and post requests. I used to wrap such requests to futures and it solves for me the "waiting problem" (I mean waiting for the response)</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defn unchangeable-lib-request [n]
    (Thread/sleep 1000)
    n)
  
  (defn process [n]
    (let [res (atom [])]
      (dotimes [i n]
        (future (swap! res conj (unchangeable-lib-request i))))
      (loop []
        (if (&gt; n (count @res))
          (recur)
          @res))))
  
  (time (process 9))
  
  ;; "Elapsed time: 1000.639079 msecs"
  ;; =&gt; [8 7 5 6 4 3 2 1 0]
  </code></pre>
  
  <p>But I need to create hundreds of requests and this creates performance problems. I found out about core.async and go blocks. But if I will use go-blocks with this library, it will not solve the "waiting problem"</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defn unchangeable-lib-request [n]
    (Thread/sleep 1000)
    n)
  
  (defn process [n]
    (let [c (async/chan 10)]
      (dotimes [i n]
        (async/go
          (async/&gt;! c (unchangeable-lib-request i))))
    (loop [result []]
      (if (&gt; n (count result))
        (recur (conj result (async/&lt;!! c)))
        result))))
  
  (time (process 9))
  
  ;; "Elapsed time: 2001.770183 msecs"
  ;; =&gt; [0 4 1 6 7 2 5 3 8]
  </code></pre>
  
  <p>Go blocks can handle just 8 requests simultaneously. Is there a possibility to write some async-wrapper that will park go-block and provide ability to make 100s of requests asynchronously without blocking each other?</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defn process [n]
    (let [c (async/chan 10)]
      (dotimes [i n]
        (async/go
          (async/&gt;! c (magic-async-parking-wrapper
                        (unchangeable-lib-request i))))
    (loop [result []]
      (if (&gt; n (count result))
        (recur (conj result (async/&lt;!! c)))
        result))))
  
  (time (process 9))
  
  ;; "Elapsed time: 1003.2563 msecs"
  </code></pre>
  
  <p>I know about async/thread but it seems that this is the same as (future ...). </p>
  
  <p>Is it possible?</p>