Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. (ns my-ns.core
  2. (:require [clojure.core.async :refer
  3. [timeout thread alt! alts! chan go-loop <! >! put! chan close!]]))
  4.  
  5. (defn takes-a-while [chan x]
  6. (println "starting long running query")
  7. (thread (Thread/sleep 5000)
  8. (put! chan x)))
  9.  
  10. (defn run-it []
  11. (let [c (chan)]
  12. (takes-a-while c 5)
  13. (go-loop []
  14. (let [[val chnl] (alts! [c (timeout 500)])]
  15. (if (= c chnl)
  16. (println "got value at last" val)
  17. (do
  18. (println "still waiting...")
  19. (recur)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement