title: How to handle infinite go-loops
body: <p>As a hobby project, I am working on an <a href="https://github.com/beatngu13/chan-fp" rel="nofollow">alternate futures and promises implementation</a> based on <a href="http://www.home.hs-karlsruhe.de/~suma0002/publications/events-to-futures.pdf" rel="nofollow">"From Events to Futures and Promises and back"</a>. The original author uses channels/events under the hood, which is why I am using <a href="https://github.com/clojure/core.async" rel="nofollow">core.async</a>. A future, expressed in pseudo <a href="https://golang.org/" rel="nofollow">Go</a> syntax, looks as follows:</p>
  
  <pre class="lang-go prettyprint-override"><code>func future(func f() (T, bool)) Future &lt;T&gt; {
      ch = newChannel ()
      spawn(func() {
          x := f()
          for { syncEvt(sndEvt(ch, x)) }
      })
      return rcvEvt(ch)
  }
  </code></pre>
  
  <p>Using valid Go syntax, type definitions and a <code>get</code> function:</p>
  
  <pre class="lang-go prettyprint-override"><code>type Comp struct {
      value interface{}
      ok    bool
  }
  
  type Future chan Comp
  
  func future(f func() (interface{}, bool)) Future {
      future := make(chan Comp)
  
      go func() {
          v, o := f()
          c := Comp{v, o}
          for {
              future &lt;- c
          }
      }()
  
      return future
  }
  
  func (ft Future) get() (interface{}, bool) {
      c := &lt;-ft
      return c.value, c.ok
  }
  </code></pre>
  
  <p>Now, when I port this to Clojure, I was thinking to implement it as followed:</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defrecord Comp [value ok])
  
  (defn future [f]
    (let [future (chan)]
      (go-loop [comp (f)]
        (&gt;! future comp)
        (recur comp))
      future))
  
  (defn get [future]
    (&lt;!! future))
  </code></pre>
  
  <p>Since I'm pretty new to Clojure (and core.async), I worry about the infinite <code>go-loop</code>. Will the IOC thread ever be released? Should I provide some kind of poison pill to stop the loop (though I think this would be pretty error-prone)? Any suggestions?</p>