Skip to content

Instantly share code, notes, and snippets.

@thheller
Created June 29, 2013 08:28
Show Gist options
  • Save thheller/5890363 to your computer and use it in GitHub Desktop.
Save thheller/5890363 to your computer and use it in GitHub Desktop.
(ns thheller.async-test
(:use clojure.test)
(:require [clojure.core.async :as async :refer (go >! <! >!! <!!)]))
(def c (async/chan))
(defn do-some-work [work]
(throw (ex-info "no way" {:work work})))
(go (loop [work-done 0]
(let [[reply-to work] (<! c)
reply (do-some-work work)]
(>! reply-to reply)
(recur (inc work-done))
)))
(let [me (async/chan)]
(>!! c [me :work-work])
(<!! me) ;; never returns
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment