Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns my-ns.core
- (:require [clojure.core.async :refer
- [timeout thread alt! alts! chan go-loop <! >! put! chan close!]]))
- (defn takes-a-while [chan x]
- (println "starting long running query")
- (thread (Thread/sleep 5000)
- (put! chan x)))
- (defn run-it []
- (let [c (chan)]
- (takes-a-while c 5)
- (go-loop []
- (let [[val chnl] (alts! [c (timeout 500)])]
- (if (= c chnl)
- (println "got value at last" val)
- (do
- (println "still waiting...")
- (recur)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement