Skip to content

Instantly share code, notes, and snippets.

@squaremo
Last active August 29, 2015 14:05
Show Gist options
  • Save squaremo/9bae15cd932dffe7e776 to your computer and use it in GitHub Desktop.
Save squaremo/9bae15cd932dffe7e776 to your computer and use it in GitHub Desktop.
(defn hello-loop [inbox outbox control]
(go-loop []
(alt! ;; choice
inbox ([name] (do
(>! outbox (str "Hello" name)) ;; put
(recur))) ;; loop
control nil)))
(let [in (chan) ;; construct a channel
out (chan)
ctrl (chan)]
(hello-loop in out ctrl) ;; cons process
(>! in "Michael") ;; put
(println (<! out)) ;; take
(close! ctrl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment